Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel inner join Query

Tags:

php

mysql

laravel

I want to change this MySQL query to Larvel Grammar.

MySql inner Join

 select u.name , c.title , c.content 
 from users u 
 inner join communities  c on u.id = c.user_id
 where u.name like '%name%'
like image 469
박보근 Avatar asked Apr 06 '26 17:04

박보근


1 Answers

Try this query:

DB::table('users')
     ->select(['users.name', 'communities.title', 'communities.content'])
     ->join('communities', 'communities.user_id', '=', 'users.id')
     ->where('users.name', 'like', '%' . $request->name . '%')
     ->get();
like image 153
Bhoomi Patel Avatar answered Apr 08 '26 05:04

Bhoomi Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!