Laravel Query with Multiple Tables Join and Multiple Join Fields
Laravel Query with Multiple Tables Join and Multiple Join Fields
I'm trying to build a query to join multiple tables with multiple join fields.
This is the code:
$crew = DB::table('crew')
->join('aclist', function ($join){
$join->on(function($query){
$query->on('aclist.ac_config', '=', 'crew.config')
->on('aclist.ac_type', '=', 'crew.ac_type');
});
})
// Error happened after I add this indexform join script
->join('indexform', function ($join){
$join->on(function($query){
$query->on('indexform.config', '=', 'crew.config')
->on('indexform.ac_type', '=', 'crew.ac_type');
});
})
->select('crew.*','indexform.*')
->where('aclist.ac_reg', $input['acreg'])
->get();
Below is the view code, and it's no longer working after I add the indexform join script
@foreach ($crew as $crw)
<tr>
<td class="container" align="center" colspan="4">{{$crw->description}}</td>
<td class="container" align="center">{{$crw->qty}}</td>
<td class="container" align="center">{{$crw->arm_meter}}</td>
<td class="container" align="center">{{$crw->weight_kg}}</td>
<td class="container" align="center">{{$crw->index}}</td>
</tr>
@endforeach
The query work well before I add the script to join the indexform tables.
Please help how to build query to join three tables with multiple "on" criteria.
The view code is no longer returning values after I add the indexform join script
– seeai
Jul 3 at 10:32
Looks like there is no data that can satisfy all constraints. Does
crew
contain entries that have matching entries in aclist
AND indexform
?– Jonas Staudenmeir
Jul 3 at 12:50
crew
aclist
indexform
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What's the error?
– Jonas Staudenmeir
Jul 2 at 6:48