Level 2
laravel support hasManyThrough or hasOneThrough just for simple relations not Polymorphic Relationships, for now look https://laravel.com/docs/eloquent-relationships
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$organization->room //conference ->booking // 1 to many polymorphic relationship room.php/model
public function bookings()
{
return $this->morphMany('App\Booking', 'bookable');
}
public function organization()
{
return $this->belongsTo(Organization::class, 'organization_id');
}
conference.php also similar with the room.php
the organization has 1 to many relationships with the room and conference.
my question is how can i get $organization->booking;
$organization->booking;
//i try hasManyThrough, but it only works either room or conference.
public function booking()
{
return $this->hasManyThrough(Booking::class, Room::class, 'organization_id','bookable_id','id','id');
}
any help please, thanks
Please or to participate in this conversation.