How to merge Laravel objects in controller

后端 未结 5 370
栀梦
栀梦 2021-02-01 04:49

I have a controller where I want to combine data from multiple tables with parallel structures. What I want to end up with in the end is one object I can return from the contro

5条回答
  •  野的像风
    2021-02-01 05:48

    What you can do here is merge the arrays of the two query result and then use the Response with json output like shown below.

    $array = array_merge($mc->toArray(), $sm->toArray());
    return Response::json($array);
    

提交回复
热议问题