Skip to content
This repository has been archived by the owner on May 5, 2019. It is now read-only.

Commit

Permalink
auto mutate space in name to hyphen
Browse files Browse the repository at this point in the history
  • Loading branch information
forehalo committed Dec 23, 2016
1 parent 39b9660 commit 1ea1a00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 29,14 @@ public function posts()
{
return $this->hasMany('App\Models\Post');
}

/**
* Mutate space to hyphen('-') in name column.
*
* @param $value
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = str_replace(' ', '-', $value);
}
}
17 changes: 17 additions & 0 deletions app/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 30,25 @@ public function posts()
return $this->belongsToMany('App\Models\Post', 'post_tag', 'tag_id');
}

/**
* Pivot table.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function postTags()
{
return $this->hasMany('App\Models\PostTag', 'tag_id');
}

/**
* Mutate space to hyphen('-') in name column.
*
* @param $value
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = str_replace(' ', '-', $value);
}


}

0 comments on commit 1ea1a00

Please sign in to comment.