laravel eloquent join query code example

Example 1: laravel where like

$users = DB::table('users')
                ->where('name', 'like', 'T%')
                ->get();

Example 2: laravel join table

$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();

Example 3: join in laravel eloquent

$customer = DB::table('customers')
                ->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
                ->where('customer_contact', $contact_no)
                ->get();

Tags:

Sql Example