I have four models: Animal(which can only be "dog" or "cat"), Category, Breed and Post.
Table data:
Animal: - id - name
Category: - id - name - animal_id
Breed: - id - name - category_id
Post: - id - breed_id
What I need is to get all Posts that are about dogs. Have any ideas?
Update: My models:
class Animal extends Model
{
public function categories()
{
return $this->hasMany(Category::class)->orderBy('name', 'ASC');
}
}
class Category extends Model
{
public function animal()
{
return $this->belongsTo(Animal::class);
}
public function breeds()
{
$this->hasMany(Breed::class)->orderBy('name', 'ASC');
}
}
class Breed extends Model
{
public function category()
{
return $this->belongsTo(Category::class);
}
public function posts()
{
return $this->hasMany(Posts::class);
}
}
class Posts extends Model
{
public function breed()
{
return $this->belongsTo(Breed::class);
}
}