Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel query with optional filter

    $cars = Car::when($request->get('make'), function ($query, $make) {
            $query->where('make', $make);
        })
        ->when($request->get('model'), function ($query, $model) {
            $query->where('model', $model);
        })
 
PREVIOUS NEXT
Tagged: #laravel #query #optional #filter
ADD COMMENT
Topic
Name
3+3 =