Good afternoon pips, I would like to ask for your help.
Could you please help me apply this query into the Laravel Query Builder. I only know how to query into the database using raw query.
Query:
SELECT users.first_name, users.last_name, users.id as userID, bookmarks.id,
products.title, products.price, products.id AS productID FROM users,
products, bookmarks WHERE bookmarks.user_id = $user_id AND products.id =
bookmarks.product_id AND users.id = products.user_id;
Thank you for those people that would help me.
Use this Laravel Query.
$response = DB::table('users as u')->select(
'u.id as userId',
'u.first_name',
'u.last_name',
'b.id as bookmarkId',
'p.id as productId',`enter code here`
'p.title',
'p.price'
)
->leftjoin('bookmarks as b', 'b.user_id', '=', 'u.id')
->leftjoin('products as p', 'p.user_id', '=', 'u.id')
->where('u.id', $userId)->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With