Convert a string to a slug in Laravel

Convert a string to a slug in Laravel

This can be achieved very easily in Laravel. First create a new column in your table called slug and add this to your fillable in the Model. Now in your create function you can simply add.
'slug' => str_slug([string])
//e.g.
'slug' => str_slug($request->title),
Make sure you add some validation so the slug is unique.

Categories: Posts