Skip to content

futurex-open-source/laravel-sluggable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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"!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages