简体   繁体   English

如何将两个查询结果合并为 Laravel Nova 并显示在资源表上

[英]How to merge two queries result in Laravel Nova and display them on the resource table

I'm trying to merge two queries results in Laravel Nova.我试图在 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.我试图覆盖indexQuery方法,但无法这样做。 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:您可以尝试以下操作,尽管在 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);我更喜欢你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.您可以在 .network 选项卡中看到结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM