Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel when

/* 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();
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel
ADD COMMENT
Topic
Name
7+6 =