【问题标题】:Laravel search filter query building with pagination使用分页构建 Laravel 搜索过滤器查询
【发布时间】:2014-06-29 01:56:47
【问题描述】:

我有一个用户输入的搜索表单,我过滤掉数据然后分页。 问题是当我对 Laravel 进行分页时会返回整个结果

$searchFilter = arrray('id'=>true);
$building = new Building();

if (isset($searchFilter['id']))
{
    $building->where('id','=', 6);

}

return $building->paginate(20);

表中只有一行 id 为 6。 Laravel 返回表格的所有行。

但是,如果我不分页,它将只返回 id 为 6 的行 我希望它通过应用 where 操作返回分页

【问题讨论】:

    标签: php laravel-4 pagination


    【解决方案1】:

    想出了答案。 我应该将它附加到 $building where 操作。这是 Laravel 流利的作品

    $searchFilter = arrray('id'=>true);
    $building = new Building();
    
    if (isset($searchFilter['id']))
    {
       // need to append it to building to make it work
        $building  = $building->where('id','=', 6);
    
    }
    
    return $building->paginate(20);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-06
      • 2018-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2022-07-30
      • 1970-01-01
      相关资源
      最近更新 更多