Laravel Combine two DB query results Example

Today, We want to share with you Laravel Combine two DB query results Example.In this post we will show you concat two columns in laravel 6 query, hear for laravel 6 join two tables using model we will give you demo and example for implement.In this post, we will learn about laravel 6 left join with relationships with an example.

Laravel Combine two DB query results Example

There are the Following The simple About Laravel Combine two DB query results Example Full Information With Example and source code.

Also Read This πŸ‘‰   Laravel 6 Eloquent LEFT JOIN Query Example Tutorial

As I will cover this Post with live Working example to develop laravel 6 select from multiple tables, so the join query in laravel 6 controller is used for this example is following below.

Combine two tables into one result set.

Laravel 6 merge/append/join

// get all film members
$filmMembers= FilmMember::all();
 
// get all new media members
$newMediaMembers=  NewMediaMember::all();
 
// merge members,
foreach($filmMembers as $filmMember) {
    $newMediaMembers->add($filmMember);
}
 
// or we can also do this $newMediaMembers->toBase()->merge($filmMembers);
 
dd($newMediaMembers->toArray());

Laravel 6 :: Combine two DB query objects

using merge() : app/routes.php

<?php

Route::get('/', function()
{
    $a = FilmMember::where('status','enable')
        ->get();
    $b = FilmMember::where('status','padding')
        ->get();

    $result = $a->merge($b);

    $result->each(function($row)
    {
        echo $row->title.'<br />';
    });
});

Web Programming Tutorials Example with Demo

Read :

Also Read This πŸ‘‰   set timezone in codeigniter - how to set timezone in codeigniter?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

Free Live Chat for Any Issue

I hope you get an idea about laravel merge two collections.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Rate this post