Search
 
SCRIPT & CODE EXAMPLE
 

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();
Comment

PREVIOUS NEXT
Code Example
Php :: carbon in laravel 
Php :: laravel get query in normal sql without bindings 
Php :: Turning a StdClass object into an array 
Php :: switch php 
Php :: php artisan preset react 
Php :: composer deploy production 
Php :: laravel vendor:publish not working 
Php :: lluminateHttpExceptionsPostTooLargeException 
Php :: laravel drop multiple columns 
Php :: laravel blade @guest 
Php :: php sessions 
Php :: how to redirect to previous page in php 
Php :: checking php version 
Php :: validate executable path vscode 
Php :: php remove html tags 
Php :: php reader read date from excel 
Php :: laravel pass view with data 
Php :: option value selected in laravel blade 
Php :: how to document php api with swagger 
Php :: php how to rename a file before saving it 
Php :: dir name php 
Php :: clear session php 
Php :: grouping routes in laravel 
Php :: laravel migration remove constraint 
Php :: create a user using tinker 
Php :: php parse url get path 
Php :: deleteall in cakephp 
Php :: laravel limit query pagination 
Php :: migration with seeder laravel 
Php :: how to retrieve value from stdclass array in php 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =