Laravel :: Combine two DB query objects

后端 未结 1 839
我寻月下人不归
我寻月下人不归 2021-02-14 08:38

I have a method in my Game model that retrieves a list of all games registered in a table on one database, iterates through every game found and fetches data from anoth

1条回答
  •  情歌与酒
    2021-02-14 09:10

    merge()

    The merge method merges the given array into the original collection. If a string key in the given array matches a string key in the original collection, the given array's value will overwrite the value in the original collection

    The only parameter to the method is the collection that should be merged. Here's an example.

    get();
        $b = Album::where('artist','Matt Nathanson')
            ->get();
    
        $result = $a->merge($b);
    
        $result->each(function($album)
        {
            echo $album->title.'
    '; }); });

    else

    $array = array_merge($stats[$game->game]->toArray(), $map->toArray()); 
    return Response::json($array);
    

    0 讨论(0)
提交回复
热议问题