I have created an index table to combine the results of 3 tables.
Tables: Chairman, Designation, Members
Index table(state_chairman_members_maps) maps members to correspondeing designation and chairman.
I have created this index to reuse the members because they could have different chairmans. Sometime the designation are same sometimes will change.
Note: chairman also have many members.
I wrote this query to acheive it,
$mapmembers = DB::table('state_chairman_members_maps')
->join('statechairmen','statechairmen.id','=','state_chairman_members_maps.chairman_id')
->join('statemembers','statemembers.id','=','state_chairman_members_maps.members_id')
->join('statedesignations','statedesignations.id','=','state_chairman_members_maps.designation_id')
->where('chairman_id','=',$id)//here passing the chairman id to find the users
->get();
I am getting result,
Here is my blade,
<tbody>
@foreach ($mapmembers as $mapmember)
<tr>
<th>
{{$mapmember->first_name}} //member table
</th>
<th>{{$mapmember->designation_name}} </th> //designation table
</tr>
@endforeach
But I would like to use the Laravel eloquent for the above query. But I am not sure how to get it. Tryo to figure out a solution for a quite while.
Would it be advisible to leave the query as it or convert to laravel eloquent.
I am okay with the above but I would like to learn how I can acheive it through Eloquent, because I have few more like this to work.
Thanks