Skip to content

kduma-OSS/LV-eloquent-sluggable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

L5-eloquent-sluggable

Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight StyleCI Build Status

Eases using and generating slugs Laravel Eloquent models.

Check full documentation here: opensource.duma.sh/libraries/php/eloquent-sluggable

Setup

Add the package to the require section of your composer.json and run composer update

"kduma/eloquent-sluggable": "^1.1"

Prepare models

Inside your model (not on top of file) add following lines:

use \KDuma\Eloquent\Slugabble;

Optionally you can add also SluggableString function which will return string from which slug will be made (default it uses title field):

protected function SluggableString(){
    return $this->year.' '.$this->title;
}  

In database create slug string field. If you use migrations, you can use following snippet:

$table->string('slug')->unique();

Usage

By default it generates slug on first save.

  • $model->newSlug() - Generate new slug. (Remember to save it by yourself)
  • Model::whereSlug($slug)->first() - Find by slug. (whereSlug is query scope)

Eric L. Barnes

A special thanks to Eric L. Barnes, an original code creator that this package is based on.

Packagist

View this package on Packagist.org: kduma/eloquent-sluggable

About

Eases using and generating slugs Laravel Eloquent models.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages