ItSolutionStuff.com

Example of unionAll in Query Builder Laravel

By Hardik Savani • November 5, 2023
PHP Laravel

Sometimes you need to bind multimple query then you can use unionAll in laravel. If you use union all then laravel query builder provide unionAll method for mysql union. when you are doing big project or ERP level project then mostly you require to use union for getting data from database with multiple table. In Following example you can see how to use union all in Laravel 5.

Example:

$silver = DB::table("product_silver")

->select("product_silver.name"

,"product_silver.price"

,"product_silver.quantity");

$gold = DB::table("product_gold")

->select("product_gold.name"

,"product_gold.price"

,"product_gold.quantity")

->unionAll($silver)

->get();

print_r($gold);

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Use DB Raw Query in Laravel?

Read Now →

Laravel E-Signature using Docusign API Tutorial

Read Now →

Laravel Login with Mobile Number OTP Tutorial

Read Now →

Laravel Login and Registration using Ajax Tutorial

Read Now →

Laravel Profile Image Upload Tutorial with Example

Read Now →

How to Add Extra Field in Registration Form in Laravel?

Read Now →

Laravel TCPDF: Generate HTML to PDF File Example

Read Now →

Laravel Group By with Max Value Query Example

Read Now →

Laravel Eloquent Order By Query Example

Read Now →

How to use Union Query with Laravel Eloquent?

Read Now →

How to Execute MySQL Query in Laravel?

Read Now →

Laravel Query Builder Where Exists Example

Read Now →