A Blog Of Random Coding Techniques & Experiments Robert Askam

Convert a string to a slug in Laravel Post Convert a string to a slug in Laravel 1 year ago

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.