Pharaonic
Loading...

# Inclusion in migration

Create a slug column on the table, Just add this line to your Migration file.

1$table->sluggable();

# Inclusion in model

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 name
12 *
13 * @var string
14 */
15 protected $sluggable = 'title';
16 
17 /**
18 * The attributes that are mass assignable.
19 *
20 * @var array
21 */
22 protected $fillable = ['title'];
23}

# Generate Slug

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

# Blade Directive

Regardless of any model, you can generate slug any string in your Blade file.

1@slug('Moamen Eltouny')