1Inner Join : ->join('contacts', 'users.id', '=', 'contacts.user_id')
2Left Join : ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
3Right Join : ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
4Cross Join : ->crossJoin('colors')
5
6Advance Queries :
7-----------------
8 ->join('contacts', function ($join) {
9 $join->on('users.id', '=', 'contacts.user_id')
10 ->where('contacts.user_id', '>', 5);
11 })
12
1DB::table('users')->insert([
2 'email' => 'kayla@example.com',
3 'votes' => 0
4]);
1/* you may only want to apply a where statement if a given input value
2is present on the incoming request.
3*/
4$role = $request->input('role');
5
6$users = DB::table('users')
7 ->when($role, function ($query, $role) {
8 return $query->where('role_id', $role);
9 })
10 ->get();
1 $customer = DB::table('customers')
2 ->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
3 ->where('customer_contact', $contact_no)
4 ->get();