I'm trying to use the Laravel's sluggable package found here: https://github.com/cviebrock/eloquent-sluggable
When I save a model (ex. Product), the sluggable feature doesn't sluggify my model. This is on a brand new install of Laravel as of today.
I can see that the event listener fires (line 43 in SluggableServiceProvider.php), but it seems as though the if ($model instanceof SluggableInterface) statement never returns true and never sluggifies my model. Could this be a name spacing issue? Any other ideas?
Here is my Product model:
<?php
use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;
class Product extends Eloquent {
use SluggableTrait;
protected $sluggable = array(
'build_from' => 'title',
'save_to' => 'slug',
);
}
I can, of course, get the sluggify method to run manually by doing something like this:
$product->sluggify();
But I would like to adhere to best practices and try to get the sluggify code to work automatically when the model save event is triggered.
add implements SluggableInterface
to your Product
class
class Product extends Eloquent implements SluggableInterface
{
}
demo code on github:
https://github.com/cviebrock/eloquent-sluggable#updating-your-eloquent-models