eloquent - Laravel: How to get relational model from 2D array of IDs -


i have array of ids $bookingpaymentpending[attendee_id][program_id] =

array(2) { [416]=> array(2) { [0]=> int(2) [1]=> int(4) }             [417]=> array(2) { [0]=> int(2) [1]=> int(4) } }  

i want collection of relational models attendee , programs. want access $attendee->programs

i this....

foreach ($bookingspaymentpending $attendee_id => $program_ids) {   $attendees[$attendee_id] = attendee::find($attendee_id)->with(['scheduled_programs' => function($q) use ($program_ids)   {     $q->wherein('id', $program_ids);   }]); } 

but $attendees isn't right because didn't know how put eloquent model. can show me how properly? there simple eloquent way this? or query builder way go?

does give expected output?

$attendees = attendee::with('scheduled_programs')     ->wherein('id', array_keys($bookingpaymentpending))     ->get();  foreach($attendees $attendee){     var_dump($attendee->scheduled_programs); } 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -