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.

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 :

Summary

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

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   View Files with FileZilla - filezilla edit file on server
  2.   PHP Laravel 6 create Pagination Example - demo
  3.   Laravel Eloquent Update increment decrement Database column value
  4.   How to insert data in database using Laravel framework
  5.   Laravel create Dynamic Email Templates from Database
  6.   Laravel 5.8 Merge Multiple Collection Paginate
  7.   Laravel Collection Push with Array Example
  8.   Laravel Convert Array To Collection Example
  9.   Registration Form Validation using Ajax in Codeigniter
  10.   Vue js Axios HTTP Post Method Example Tutorial From Scratch