sunel / eav

Entity–attribute–value model (EAV) for Laravel Artisan

Home Page:https://sunel.github.io/eav/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Model Event ignored

divdax opened this issue · comments

I've an entity App\Product and using the spatie/laravel-sluggable package to create a slug for each product.

The slug is defined as a static attribute and the column slug is available on the products table but when a product is created no slug is inserted.

Even with a basic boot method to listen for events on my Product model this is ignored:

public static function boot()
{
    parent::boot();

    static::creating(function($data) {
        $data->slug = 'test';
    });
}

The core snippet from the package is using the magic boot mechanism like so:

HasSlug Trait:

protected static function bootHasSlug()
{
    static::creating(function (Model $model) {
        $model->generateSlugOnCreate();
    });

    static::updating(function (Model $model) {
        $model->generateSlugOnUpdate();
    });
}

@sunel Yes, like i said in my post. 😄

The slug is defined as a static attribute and the column slug is available on the products table but when a product is created no slug is inserted.

Attributes table
Bildschirmfoto 2020-01-19 um 10 52 17

Products table
Bildschirmfoto 2020-01-19 um 10 53 07

@divdax

Can you dump the data from $mainData from this line

https://github.com/sunel/eav/blob/master/src/Model.php#L235

@sunel here the dump:

array:7 [
  "name" => "test"
  "slug" => null
  "description" => "asd"
  "attribute_set_id" => 1
  "entity_id" => 1
  "updated_at" => "2020-01-22 00:08:39"
  "created_at" => "2020-01-22 00:08:39"
]

@sunel Any idea why slug is empty, or do you need any further informations to reproduce the problem?

@divdax

Can you pull the latest tag and check.

@sunel

✅pull
✅check
✅it works!

🎉 Thank you! I really appreciate your work you put into this package!