Replies: 1 comment 1 reply
-
Hi ✋🏻 You could try this: 1.- Create an observer to listen the <?php
namespace App\Observers;
use Illuminate\Database\Eloquent\Model as Eloquent;
class EloquentObserver
{
/**
* Handle the eloquent "created" event.
*
* @param \App\Models\Eloquent $eloquent
* @return void
*/
public function created(Eloquent $eloquent)
{
//
}
/**
* Handle the eloquent "updated" event.
*
* @param \App\Models\Eloquent $eloquent
* @return void
*/
public function updated(Eloquent $eloquent)
{
//
}
// The rest of the observer's methods...
} 2.- Define this in the /**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
// We can not instanciate Illuminate\Database\Eloquent\Model
// so we create a new instance of each model
$models = [
new \App\Models\User,
new \App\Models\Post,
// The rest of your models...
];
collect($models)->each->observe(EloquentObserver::class);
} With this, any |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
Is there a way to listen to all model event rather than creating observer to each model?
We have numerous models that needs to clear its cache in every update. Implementing listener or booting event to each model seems too tedious for us now.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions