In this tutorial, we will see how to use union query in laravel application.
The use of laravel union query used to get matches record.
Query 1:
$first = DB::table('users')
->where('id',8);
$users = DB::table('users')
->where('id',2)
->union($first)
->get();
Query 2 with Model
$first = User::where('id',8);
$users = User::where('id',2)->union($first)->get();
I hope this example helps you.