duyduc-nguyen / laravel-sluggable-trait
Create unique slugs for your Eloquent models in Laravel. Support Cache
0.1.2
2015-10-25 04:06 UTC
Requires
- php: >=5.4.0
- illuminate/database: >=4.0
- illuminate/support: >=4.0
This package is not auto-updated.
Last update: 2024-11-23 19:58:55 UTC
README
Create unique slugs for your Eloquent models in Laravel. Support Cache
Install
$ composer require duyduc-nguyen/laravel-sluggable-trait
Usage
<?php namespace App; use Illuminate\Database\Eloquent\Model; use DuyDucNguyen\Database\Traits\SluggableTrait; class Item extends Model { use SluggableTrait; }
First, you need to indicate sluggable column and slug column of your model via class constants:
<?php namespace App; use Illuminate\Database\Eloquent\Model; use DuyDucNguyen\Database\Traits\SluggableTrait; class Item extends Model { use Sluggable; const SLUGGABLE_COLUMN = 'title'; const SLUG = 'slug'; }
If you need to improve your query for searching slug, you can enable Laravel Cache for caching slug via
const ENABLE_SLUG_CACHE = true;
License
Licensed under the MIT Licence.