Answers for "laravel join"

PHP
16

laravel join

Inner Join 	: ->join('contacts', 'users.id', '=', 'contacts.user_id')
Left Join 	: ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
Right Join 	: ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
Cross Join 	: ->crossJoin('colors')

Advance Queries : 
----------------- 
 		->join('contacts', function ($join) {
            $join->on('users.id', '=', 'contacts.user_id')
                 ->where('contacts.user_id', '>', 5);
        })
Posted by: Guest on August-13-2020
4

laravel join

use Illuminate\Support\Facades\DB;

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();
Posted by: Guest on December-09-2020
3

laravel join

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();
Posted by: Guest on April-29-2020
7

laravel wher in

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();
Posted by: Guest on April-30-2020
3

join in laravel eloquent

$customer = DB::table('customers')
                ->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
                ->where('customer_contact', $contact_no)
                ->get();
Posted by: Guest on October-06-2020
2

laravel join

$latestPosts = DB::table('posts')
                   ->select('user_id', DB::raw('MAX(created_at) as last_post_created_at'))
                   ->where('is_published', true)
                   ->groupBy('user_id');

$users = DB::table('users')
        ->joinSub($latestPosts, 'latest_posts', function ($join) {
            $join->on('users.id', '=', 'latest_posts.user_id');
        })->get();
Posted by: Guest on August-13-2020

Browse Popular Code Answers by Language