I'm trying to merge two queries results in Laravel Nova. I've gone through the documentation but haven't found a solution. Basically, I'd like to merge two queries results and show them in a resource table.
I tried to override the indexQuery
method but was unable to do so. reference
public static function indexQuery(NovaRequest $request, $query){
$query_1 = Model::where('some condition')->get();
$query_2 = Model2::where('some condition')->get();
//merge both queries result
$result = $query_1->merge($query_2);
return $result
}
You can try the following, although its a weird way to do this in nova:
$query_1 = Model::where('some condition')->get()->toArray();
$query_2 = Model2::where('some condition')->get()->toArray();
$result = collect(array_merge($query_1, $query_2));
I prefer that you dd($result);
before passing it back to the fields to make sure you structure the fields according to your new collection. You can see the results in the.network tab.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.