I have to merge results from multiple tables in Laravel. Currently I am using the following way:
public function getMachines(Request $request) {
$vendor_id = Auth::id();
$ml_8_machine=ML8Machine::where('vendor_id','=',$vendor_id)->get();
$ml_16_machine=ML16Machine::where('vendor_id','=',$vendor_id)->get();
$ml_32_machine=ML32Machine::where('vendor_id','=',$vendor_id)->get();
$ml_64_machine=ML64Machine::where('vendor_id','=',$vendor_id)->get();
$ml_96_machine=ML96Machine::where('vendor_id','=',$vendor_id)->get();
$ml_128_machine=ML128Machine::where('vendor_id','=',$vendor_id)->get();
$machines = collect($ml_8_machine)
->merge($ml_16_machine)
->merge($ml_32_machine)
->merge($ml_64_machine)
->merge($ml_96_machine)
->merge($ml_128_machine);
return view('vendor.machines', compact('machines'));
}
I am looking for an efficient way to do the query and merge result in one collection.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2vzEhIQ
via IFTTT
Aucun commentaire:
Enregistrer un commentaire