first laravel query code example
Example 1: laravel query builder select first
$user = DB::table('users')->where('name', 'John')->first();
var_dump($user->name);
Example 2: when in larevel
$role = $request->input('role');
$users = DB::table('users')
->when($role, function ($query, $role) {
return $query->where('role_id', $role);
})
->get();
Example 3: laravel having
$users = DB::table('users')
->groupBy('account_id')
->having('account_id', '>', 100)
->get();