laravel eloquent select code example
Example 1: laravel where like
$users = DB::table('users')
->where('name', 'like', 'T%')
->get();
Example 2: laravel not in query
DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();
Example 3: laravel update from query
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
Example 4: laravel join table
$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();
Example 5: join in laravel eloquent
$customer = DB::table('customers')
->join('shops', 'customers.shop_id', '=', 'shops.shop_id')
->where('customer_contact', $contact_no)
->get();
Example 6: laravel db::query update
DB::table('user')->where('email', $userEmail)->update(array('member_type' => $plan));