We can merge easily laravel’s query result with another result object, by using laravel’s Collections method called merge(), It will merge a collection with another collection, and return a single collection containing all the elements in the two objects.
// get all film projects $filmProjects= FilmProject::all(); // get all new media projects $newMediaProjects= NewMediaProject::all(); // merge projects, foreach($filmProjects as $filmProject) { $newMediaProjects->add($filmProject); } // or we can also do this $newMediaProjects->toBase()->merge($filmProjects); dd($newMediaProjects->toArray());
That’s it.