How to merge Laravel objects in controller

后端 未结 5 460
栀梦
栀梦 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:51

    Route::get('test', function(){
        $rank = Rank::get();
        $policy = Policy::get();
        $obj = (object)array_merge_recursive((array)$rank , (array)$policy);
        var_dump($obj);
    });
    

    This is working for me. Instead of array_merge use array_merge_recursive().

提交回复
热议问题