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();
});
}
Have you mentioned slug
as Static Attribute
https://sunel.github.io/eav/master/ideology/static-attribute.html
https://sunel.github.io/eav/master/ideology/attribute.html#add
@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.
Can you dump the data from $mainData
from this line
@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?
✅pull
✅check
✅it works!