Eloquent events via closures break the Resource page

My model has a event like this:
public static function boot(): void
{
static::created(function (Rating $rating): void {
$rating->ratable->recalculateRating();
});
}
public static function boot(): void
{
static::created(function (Rating $rating): void {
$rating->ratable->recalculateRating();
});
}
When I un-comment this method the recourse page breaks, is this a known issue? The resource page itself is quite simple (created with the --generate command)
Solution:
it does
Jump to solution
5 Replies
Patrick Boivin
What error are you getting exactly?
dvdty
dvdtyOP2y ago
Undefined array key "App\Models\Rating" this is where it's coming from: /vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php
protected function initializeTraits()
{
foreach (static::$traitInitializers[static::class] as $method) {
$this->{$method}();
}
}
protected function initializeTraits()
{
foreach (static::$traitInitializers[static::class] as $method) {
$this->{$method}();
}
}
wyChoong
wyChoong2y ago
does it works if not in filament context?
Solution
dvdty
dvdty2y ago
it does
dvdty
dvdtyOP2y ago
Just found the fix I had to add parent::boot(); in the override boot method

Did you find this page helpful?