Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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);
        })
  
Comment

join 2 tables laravel

use IlluminateSupportFacadesDB;

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

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

laravel joins

// Basic Join Statement
DB::table('users')
          ->join('contacts', 'users.id', '=', 'contacts.user_id')
          ->join('orders', 'users.id', '=', 'orders.user_id')
          ->select('users.id', 'contacts.phone', 'orders.price')
          ->get();
// Left Join Statement
DB::table('users')
      ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
      ->get();
// select * from users where name = 'John' or (votes > 100 and title <> 'Admin')
DB::table('users')
          ->where('name', '=', 'John')
          ->orWhere(function($query)
          {
              $query->where('votes', '>', 100)
                    ->where('title', '<>', 'Admin');
          })
          ->get();
Comment

join in laravel eloquent

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

laravel joins

// Basic Join Statement
DB::table('users')
          ->join('contacts', 'users.id', '=', 'contacts.user_id')
          ->join('orders', 'users.id', '=', 'orders.user_id')
          ->select('users.id', 'contacts.phone', 'orders.price')
          ->get();
// Left Join Statement
DB::table('users')
      ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
      ->get();
// select * from users where name = 'John' or (votes > 100 and title <> 'Admin')
DB::table('users')
          ->where('name', '=', 'John')
          ->orWhere(function($query)
          {
              $query->where('votes', '>', 100)
                    ->where('title', '<>', 'Admin');
          })
          ->get();
Comment

join in laravel

$subCategories = Subcategory::join('categories', 'subcategories.category_id', '=', 'categories.id')
                              ->select('subcategories.*', 'categories.name AS cname')
                              ->orderBy('id', 'desc')
                              ->get();
Comment

how to join two tables in laravel

use IlluminateSupportFacadesDB;
//in the following example we will join two tables
//a products table and categories table
$categoryProducts = Product::join('categories', 'categories.id', '=', 'products.category_id')
        ->select('products.*', 'categories.category_name')
        ->where('products.status', 1)
        ->get();
Comment

how to use join in laravel 5.4

DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.id', 'contacts.phone', 'orders.price')
            ->get();
Comment

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

laravel outer join

->join('answers as answers', 'responses.answer_id', '=', 'answers.id', 'left outer')
Comment

laravel join

$query = DB::table('posts')
            ->select('posts.*',
                    'subcategories.subcategory_title_en',
                    'subcategories.subcategory_title_bn',
                    'categories.category_title_en',
                    'categories.category_title_bn',
                    'users.*',
                    'postimages.postimage_thumbnail'
                    )
            ->join('subcategories', 'subcategories.subcategory_id', '=', 'posts.subcategory_id')
            ->join('categories', 'categories.category_id', '=', 'subcategories.parent_category_id')
            ->join('users', 'users.id', '=', 'posts.user_id')
            ->join('postimages', 'postimages.post_id', '=', 'posts.post_id')->groupBy('posts.post_id');
Comment

laravel joins

DB::table('users')
        ->join('contacts', function ($join) {
            $join->on('users.id', '=', 'contacts.user_id')->orOn(/* ... */);
        })
        ->get();
Comment

PREVIOUS NEXT
Code Example
Php :: round numnero php 
Php :: php in javascript 
Php :: php artisan vendor:publish 
Php :: message mkdir() invalid path filename drivers/session_files_driver.php 
Php :: laravel where first 
Php :: add request data in laravel request 
Php :: difference of two dates in seconds php 
Php :: php json string to associative array 
Php :: php delete array element 
Php :: php convert mb to bytes 
Php :: php isset ternary operator 
Php :: php.ini path 
Php :: check session php 
Php :: php reduce 
Php :: laravel migration two primary key 
Php :: laravel withHas 
Php :: how to mask phone number in php 
Php :: php imap install 
Php :: create laravel 9 auth 
Php :: laravel custom attributes 
Php :: laravel blade upper case 
Php :: laravel tinker generate password 
Php :: laravel composer update 
Php :: PHP time limit (max_execution_time): 
Php :: php get current month first date 
Php :: laravel elasticsearch migration in laravel 
Php :: eloquent limit vs take 
Php :: php remove anchor tag from string 
Php :: php connect to mysql 
Php :: wordpress get attachment url by size 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =