Support the ongoing development of →
Artisan Laravel

Hi @gauravs456 ,

The better way to get your expected output is to use joins. The example of the same is given below:

Eloquent Query

     $result = User::select(
                            " as order_name"
                        ->leftJoin("orders", "orders.userid", "=", "")

SQL Query

select `users`.`id`, `users`.`name`, `orders`.`name` as `order_name` 

	from `users` 

	left join `orders` on `orders`.`userid` = `users`.`id`;

Hope this helps you in getting your expected output.


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.