Laravel DB Inserr
DB::table('users')->insert([
'email' => '[email protected]',
'votes' => 0
]);
Helpful Hoopoe
DB::table('users')->insert([
'email' => '[email protected]',
'votes' => 0
]);
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);
})
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();
/* you may only want to apply a where statement if a given input value
is present on the incoming request.
*/
$role = $request->input('role');
$users = DB::table('users')
->when($role, function ($query, $role) {
return $query->where('role_id', $role);
})
->get();
$customer = DB::table('customers')
->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
->where('customer_contact', $contact_no)
->get();