Aronaman
1 month ago
103
1
Laravel

relationship

Posted 1 month ago by Aronaman

$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 sign in or create an account to participate in this conversation.