You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@driesvints Can we make Model->fireModelEvent() and touchOwners() a public method?
These methods cannot be used in trait and i think thats where it is likely for packages to call these methods.
Given below snippet i would like to delete a model children relationship when the model is deleting.
static::deleting(function($model) {
$model->children->each->delete();
});
// will run duplicate queries
As it is not good to run duplicate db queries when you can actual run the query once.
It will be better to delete children with a single db query.
static::deleting(function($model) {
$model->children->map(function ($child){
// subscribers will receive deleting event on model$child->fireModelEvent('deleting'); // Error fireModelEvent not found// Here, we'll touch the owning models, verifying these timestamps get updated// // for the models. This will allow any caching to get broken on the parents// // by the timestamp. Then we will go ahead and delete the model instance.$child->touchOwners(); // Error touchOwners not found
});
$model->children()->delete();
});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
@driesvints Can we make
Model->fireModelEvent()
andtouchOwners()
a public method?These methods cannot be used in trait and i think thats where it is likely for packages to call these methods.
Given below snippet i would like to delete a model children relationship when the model is deleting.
As it is not good to run duplicate db queries when you can actual run the query once.
It will be better to delete children with a single db query.
Beta Was this translation helpful? Give feedback.
All reactions