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

left join in laravel

$data = DB::table('post')
  ->leftJoin('category', 'post.category', '=', 'category.id')
  ->leftJoin('users', 'post.author', '=', 'users.id')
  ->orderBy('created_at', 'DESC')
  ->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

left join laravel

$users = DB::table('users')
            ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();

$users = DB::table('users')
            ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
            ->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

PREVIOUS NEXT
Code Example
Php :: sanctum auth check? 
Php :: laravel collection slice 
Php :: Fatal error: Allowed memory size of 1610612736 bytes exhausted but already allocated 1.75G 
Php :: laravel where json contains 
Php :: convert date to timestamp in laravel builder 
Php :: php call class dynamically 
Php :: laravel log build 
Php :: how to collapse array in laravel 
Php :: string convert snake case to title case in laravel 
Php :: php switch case multiple values per line 
Php :: php get filetype 
Php :: wp_create_user 
Php :: laravel range query 
Php :: php check if string contains words from array 
Php :: php exponential operator 
Php :: eloquent update row response 
Php :: php array sort by key value 
Php :: laravel starter kit installation 
Php :: delete model laravel 
Php :: remove element from xml on php 
Php :: wp_enqueue_script 
Php :: WooCommerce cart API php 
Php :: migration rename column laravel 
Php :: wordpress get local date 
Php :: laravel fortify 
Php :: how do we calculate average in laravel 8 
Php :: laravel execute command from terminal 
Php :: php mysql prepare query 
Php :: laravel validation array input 
Php :: laravel eloquent select case when 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =