简体   繁体   中英

Laravel 4 Advanced Search Query

I've created a search form with several optional fields but when trying to include these as part of a query in the controller it returns no results

$active = Input::get('active');
$field  = Input::get('field');
$value  = Input::get('value');

$claims = Claim::where($field, $value);

if($active != 'All')
{
    $claims->where('active', $active);
}

$claims->get();

return View::make('admin.search.results')->with('claims', $claims);

Can anyone point out where I'm going wrong?

Try this:

$claims = Claim::where($field, $value);

if($active != 'All') {
    $claims = $claims->where('active', $active);
}

$claims = $claims->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM