First install the package with composer composer require cviebrock/eloquent-sluggable
and simply put this code in your model
use Cviebrock\EloquentSluggable\Sluggable;
class Post extends Model
{
    use Sluggable;
    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }
}
it will automatically use title as a slug
for more feature, maybe you want to read the documentations
thanks for reading, if you have a better method, feel free to discuss
 

 
    
Top comments (0)