LaravelPackages.net
Acme Inc.
Toggle sidebar
ifranksmith/laravel-sluggable

Laravel slug maker trait

315
2
About ifranksmith/laravel-sluggable

ifranksmith/laravel-sluggable is a Laravel package for laravel slug maker trait. It currently has 2 GitHub stars and 315 downloads on Packagist. Install it with composer require ifranksmith/laravel-sluggable. Discover more Laravel packages by ifranksmith or browse all Laravel packages to compare alternatives.

Last updated

Laravel Favorite (Laravel 5, 6 Package)

Allows Laravel Eloquent models to implement a 'sluggable' feature.

Index

Installation

  1. Install the package via Composer
$ composer require ifranksmith/laravel-sluggable
  1. In Laravel >=5.5 this package will automatically get registered. For older versions, update your config/app.php by adding an entry for the service provider.
'providers' => [
    // ...
    IFrankSmith\Sluggable\SluggableServiceProvider
];

Usage

Your models should import the Traits/Sluggable.php trait and use it. (see an example below):

use IFrankSmith\Sluggable\Traits\Sluggable;

class Posts extends Model
{
	use Sluggable;
}

By default, this package will generate slug from the 'name' property of the mmodel and save it to the 'slug' property of the model.

However, if your model does not use those properties, you need to create a method on your model that returns the respective column and source. For example, if you want to make slug from 'title' to 'title_slug' property, you need to use it as shown below

use IFrankSmith\Sluggable\Traits\Sluggable;

class Posts extends Model
{
    use Sluggable;
    
    public function sluggable()
    {
        return [
            "column" => "title_slug",
            "source" => "title",
        ];
    }
}

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

Comments