Level 49
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
1 like
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);
}
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
Please or to participate in this conversation.