Skip to content

Updating your Eloquent Models

Shipu Ahamed edited this page Sep 3, 2016 · 1 revision

Updating your Eloquent Models

Your models should use the Sluggable trait, which has an abstract method sluggable() that you need to define. This is where any model-specific configuration is set (see Configuration below for details):

use Cviebrock\EloquentSluggable\Sluggable;

class Post extends Model
{
    use Sluggable;

    /**
     * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }

}

Of course, your model and database will need a column in which to store the slug. You will need to add this manually via a migration.

(Previous versions of the package included an artisan sluggable:table command to assist you. This has been deprecated because it's easy enough to generate your own migrations with artisan make:migration).

That's it ... your model is now "sluggable"!

Clone this wiki locally