“laravel join” Coderfunda Code Answer’s
laravel join
23
1
Inner Join : ->join('contacts', 'users.id', '=', 'contacts.user_id')
2
Left Join : ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
3
Right Join : ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
4
Cross Join : ->crossJoin('colors')
5
6
Advance Queries :
7
-----------------
8
->join('contacts', function ($join) {
9
$join->on('users.id', '=', 'contacts.user_id')
10
->where('contacts.user_id', '>', 5);
11
})
12
laravel join
6
1
use Illuminate\Support\Facades\DB;
2
3
$users = DB::table('users')
4
->join('contacts', 'users.id', '=', 'contacts.user_id')
5
->join('orders', 'users.id', '=', 'orders.user_id')
6
->select('users.*', 'contacts.phone', 'orders.price')
7
->get();
Source: laravel.com
laravel join
php
8
1
$users = DB::table('users')
2
->join('contacts', 'users.id', '=', 'contacts.user_id')
3
->join('orders', 'users.id', '=', 'orders.user_id')
4
->select('users.*', 'contacts.phone', 'orders.price')
5
->get();
Source: laravel.com
join in laravel eloquent
4
1
$customer = DB::table('customers')
2
->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
3
->where('customer_contact', $contact_no)
4
->get();
laravel wher in
7
1
$users = DB::table('users')
2
->whereIn('id', [1, 2, 3])
3
->get();
laravel join
3
1
$latestPosts = DB::table('posts')
2
->select('user_id', DB::raw('MAX(created_at) as last_post_created_at'))
3
->where('is_published', true)
4
->groupBy('user_id');
5
6
$users = DB::table('users')
7
->joinSub($latestPosts, 'latest_posts', function ($join) {
8
$join->on('users.id', '=', 'latest_posts.user_id');
9
})->get();
Source: laravel.com
0 comments:
Post a Comment
Thanks