R
R
Rishat Sultanov2019-09-23 13:17:25
Laravel
Rishat Sultanov, 2019-09-23 13:17:25

Why doesn't Sluggable work from within a package?

I have a Category model and it uses
use Cviebrock\EloquentSluggable\Sluggable;

<?php
 
namespace App\Models;
 
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
use Cviebrock\EloquentSluggable\Sluggable;
use Kalnoy\Nestedset\NodeTrait;
 
class Category extends Model
{
    use HasTranslations;
    use NodeTrait, Sluggable {
        Sluggable::replicate as replicateSluggable;
        NodeTrait::replicate insteadof Sluggable;
    }
 
    public $translatable = ['name'];
    protected $table = 'categories';
    protected $fillable = ['name', 'slug', 'parent_id', 'owner'];
 
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'name'
            ]
        ];
    }
}

I decided to put it in a package and pull it out of the package to create categories, but the sluggable does not work in the normal way, what could be the reason?
I'm attaching screenshots from tinker where I'm trying to create a category from under different spaces:
App/Models/Category works out sluggable with a bang.
5d889b6275752448514791.png
StarterKit\Core\Models\Category also the same model only in the package does not want to throw sluggable.
5d889b88cbb9a756127209.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-09-23
@JhaoDa

[Vanga-mode-on] Because you didn't register the model observer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question