Created
January 2, 2017 06:53
-
-
Save logaretm/fa7bd58b1ae8adcb9d102cc7a6ba3518 to your computer and use it in GitHub Desktop.
Revisions
-
logaretm created this gist
Jan 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php namespace App\Traits; trait Sluggable { /** * Boots the sluggable trait. */ public static function bootSluggable() { static::saving(function ($model) { if (! $model->exists) { $model->slug = str_slug($model->{$model->getSluggableSource()}); } }); } /** * @return string */ protected function getSluggableSource() { if (property_exists($this, "sluggableSource")) { return $this->{"sluggableSource"}; } return "name"; } }