F
Filament16mo ago
dvdty

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
Patrick Boivin16mo ago
What error are you getting exactly?
dvdty
dvdtyOP16mo 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
wyChoong16mo ago
does it works if not in filament context?
Solution
dvdty
dvdty16mo ago
it does
dvdty
dvdtyOP16mo ago
Just found the fix I had to add parent::boot(); in the override boot method
Want results from more Discord servers?
Add your server