How to merge two query results and display them on resource table in Laravel Nova
P粉755863750
P粉755863750 2024-01-16 16:36:45
0
1
458

I'm trying to merge the results of two queries in Laravel Nova. I've read the documentation but haven't found a solution yet. Basically, I want to merge two query results and display them in a resource table.

I tried overriding the indexQuery method but failed. refer to

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
}

P粉755863750
P粉755863750

reply all(1)
P粉744691205

You can try the following, although the way to do it in nova is weird:

$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 dd($result); before passing it back to the field to ensure the field is built based on the new collection. You can view the results in the Network tab.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template