Laravel 8 Left Join Query Example

Laravel 8 Left Join Query Example
Laravel 8 Left Join Query Example
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
select `users`.`id`, `users`.`name`, `users`.`email`, `countries`.`name` as `country_name` 
from `users`
left join `countries` on `countries`.`id` = `users`.`country_id`
public function index()
{
$users = User::select('users.id', 'users.name', 'users.email', 'countries.name as country_name')
->leftJoin('countries', 'countries.id', '=', 'users.country_id')
->get();
}
$users = DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();
User::leftJoin('posts', 'users.id', '=', 'posts.user_id')
->select('users.*')
->where('is_published', true)
->where('views','>=','100')
->get();

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Websolutionstuff

Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.