Background: What is a slug?
A slug is a simplified version of a string, typically URL-friendly. The act of “slugging” a string usually involves converting it to one case, and removing any non-URL-friendly characters (spaces, accented letters, ampersands, etc.). The resulting string can then be used as an indentifier for a particular resource.
For example, I have a blog with posts. I could refer to each post via the ID:
… but that’s not particularly friendly (especially for SEO). You probably would prefer to use the post’s title in the URL, but that becomes a problem if your post is titled “My Dinner With André & François”, because this is pretty ugly too:
The solution is to create a slug for the title and use that instead. You might want to use Laravel’s built-in
Str::slug() method to convert that title into something friendlier:
A URL like that will make users happier (readable, easier to type, etc.).
For more information, you might want to read this description on Wikipedia.
Slugs tend to be unique as well. So if I wrote another post with the same title, I’d want to distinguish between them somehow, typically with an incremental counter added to the end of the slug:
http://example.com/post/my-dinner-with-andre-francois http://example.com/post/my-dinner-with-andre-francois-1 http://example.com/post/my-dinner-with-andre-francois-2
This keeps URLs unique.
The Eloquent-Sluggable package for Laravel 5 will handle all of this for you automatically, with minimal configuration at the start.