Is this even possible? In every tutorial that I read there is nothing about deleting, only selecting and inserting related models.
This is my problem:
I have three levels of nesting. I have classes Package, Level, Lesson and Phase, and their models are below. First one - packages:
class Package extends Eloquent {
protected $table = 'packages';
public $timestamps = false;
public function levels(){
return $this->hasMany('Level', 'package_id');
}
}
Levels:
class Level extends Eloquent {
protected $table = 'levels';
public function lessons(){
return $this->hasMany('Lesson', 'level_id');
}
public function package(){
return $this->belongsTo('Package', 'package_id');
}
}
Lessons:
class Lesson extends Eloquent {
protected $table = 'lessons';
public function phases(){
return $this->hasMany('Phase', 'lesson_id');
}
public function level(){
return $this->belongsTo('Level', 'level_id');
}
}
What I'm trying to do here is to when deleting one package i delete all levels related to it and also to delete all lessons related to those levels.
I have tried couple of options and they were all wrong, I just don't know how to do this without making a bunch of queries in foreach loop. Please, give some advice I'm so desperate I'm thinking about tweet to Jeffrey Way and ask him for the solution :) Thanks in advance