I have a typical event hook for soft deleting children:
public static function boot()
{
parent::boot();
static::deleted(function($model1)
{
$model1->hasmanyrelation()->delete();
});
}
and
public function hasmanyrelation()
{
return $this->hasMany('Model2');
}
Now when I use:
$model0->model1->each(function($model1){$model1->delete();});
things work as expected and model2 children of model 1 get (soft) deleted. But when I use:
$model0->model1()->delete();
then all related model1 records get deleted but model2 and all its records remain untouched. What is wrong with the latter, simpler syntax that it deletes model1 records but skips its mode events??
A little confusing what does the model1() method do?
model1()->delete()
$model1->delete()
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community