Unique slug generator in Laravel

Generating unique slug is sometimes hard to figure out. But this is really simple if you know what your are doing.

When storing content in the database a typical pattern for retrieving it is to create a unique “slug” based on the title. This gives users and search engines a human-friendly way to access it through the URL.

Here is a gist to demonstrate the generation of unique slug.

You can use str_slug() helper function instead of using Str:slug() static method.

Scroll to Top