Create a slug column on the table, Just add this line to your Migration file.
1$table->sluggable();
This is how you can include Sluggable into your model.
1namespace App\Models; 2 3use Illuminate\Database\Eloquent\Model; 4use Pharaonic\Laravel\Sluggable\Sluggable; 5 6class Article extends Model 7{ 8 use Sluggable; 9 10 /**11 * Sluggable attribute's name12 *13 * @var string14 */15 protected $sluggable = 'title'; 16 17 /**18 * The attributes that are mass assignable.19 *20 * @var array21 */22 protected $fillable = ['title'];23}
The slug will generate on Create/Update your model so don't worry about it.
1$article = Article::create(['title' => 'Moamen Eltouny']);2echo $article->slug; // moamen-eltouny
Regardless of any model, you can generate slug any string in your Blade file.
1@slug('Moamen Eltouny')