I my opinion there is nothing wrong with this approach. But if you want to generate the slugs automatically for your Eloquent models you could also have a look at this repo: https://github.com/cviebrock/eloquent-sluggable
Oct 23, 2014
4
Level 20
Auto generate a slug
I have a "Name" field that has to be unique. I want to generate a slug from that name. Is this the best way to go about it? It seems a bit hacky to me.
public function setNameAttribute($name)
{
$this->attributes['name'] = $name;
$this->attributes['slug'] = Str::slug($name);
}
Level 49
1 like
Please or to participate in this conversation.