New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear menu-cache when deleting items #4083
Conversation
Instead of overriding Eloquent's save/destroy function, you could use events: https://laravel.com/docs/5.8/eloquent#events |
But this would introduce a whole new file to just call one method. |
@emptynick please reconsider your approach, using events doesn't always imply creating an observer, you can just add it in the model boot method: public static function boot()
{
parent::boot();
static::deleted(function ($model) {
$model->removeMenuFromCache();
});
static::saved(function ($model) {
$model->removeMenuFromCache();
});
} Also I think your destroy method will only remove Cache from the first Menu in the really remote case someone is going to delete more than one menu at the same time. |
Those static-anonymous functions have a lot of disadvantages. I made it observed by another class now. |
$model is passed as parameter, it works for me and it's the way I always used it and saw in examples.
good 👍 |
Yes, but for menu-items you need to get the parent menu by calling a not-static method |
$model->menu->removeMenuFromCache(); also works from MenuItem |
My preference is leaning toward the events approach. |
Done |
When a menu-item is destroyed, the
save
method is not called, thus the menu-cache is not cleared.This PR adds cache-clearing when an item/menu is deleted
Fixes #4071