laravel db where code example

Example 1: laravel wher in

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

Example 2: laravel db::query update

DB::table('user')->where('email', $userEmail)->update(array('member_type' => $plan));

Example 3: laravel db query

$users = DB::table('users')
            ->where('votes', '>', 100)
            ->orWhere(function($query) {
                $query->where('name', 'Abigail')
                      ->where('votes', '>', 50);
            })
            ->get();

Example 4: DB::table('users')->get();

DB::table('users')->where('name', Input::get('name'))->get();

Example 5: db name laravel

DB::connection()->getDatabaseName() //laravel

Example 6: laravel having

$users = DB::table('users')
                ->groupBy('account_id')
                ->having('account_id', '>', 100)
                ->get();

Tags:

Sql Example