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

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

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 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 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 :: Laravel 5.4 Route back in blade 
Php :: allowed memory size of bytes exhausted composer 
Php :: laravel collection prepend 
Php :: PHP Function to create GUID 
Php :: call php from html 
Php :: applying multiple order by in codeigniter 
Php :: The `url` supplied for the path (./nova) repository does not exist 
Php :: create listener using laravel 
Php :: var_dump php 
Php :: laravel deleted controller still cached 
Php :: static modal 
Php :: angular post phph 
Php :: current user wordpress 
Php :: foreach reverse laravel 
Php :: php not recognized 
Php :: laravel unique column except self 
Php :: factorial function php 
Php :: how to make doctrine schema update in symfony 2.8 
Php :: php hash 
Php :: laravel range query 
Php :: how to get product id by sku in woocommerce 
Php :: php save array in mysql database 
Php :: php new stdClass object 
Php :: dump php array into javascript array 
Php :: echo all php global variables 
Php :: wp_enqueue_script 
Php :: php echo sql result 
Php :: laravel collection reduce 
Php :: Displaying the category name of a custom post type 
Php :: emergency password reset script wordpress 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =