I am using laravel 9, PHP 8.1.
I noticed the following problem:
// App\Model\Store
class Store extends Model
{
....
public function scopeUpdateStore($query, $id) {
Store::find($id)->update(['name' => 'foo']);
return $query;
}
}
Then if I use :
Store::updateStore($id)->first();
Event updating
and updated
will not fire.
But when I use in controller:
// StoreController
Store::find($id)->update(['name'])
Event updating
and updated
will fire.
My problem is that it is not clear why there is this difference, and is there a way to make the event fireable in the Query Scope
?
Thank you very much.