Laravel unique slug generator

Rakibul Islam
1 min readJun 7, 2020

--

Laravel Slug Generator

Want to generate unique slug in Laravel? Its pretty easy. Lets try.

First of all you should have a `slug` column in your Model. Suppose you have Post model. add this code inside model class,

Now you can call slugify method anywhere using post object for generate unique slug. Assume, you want to store a post with slug. in PostController you can easily generate slug and store into database.

--

--

Rakibul Islam
Rakibul Islam

Written by Rakibul Islam

Passionate PHP Expert, Love to make things that make a difference! You can find me here, https://www.linkedin.com/in/rakibhstu/

Responses (2)