0

我正在为客户创建一个允许多个选项的搜索表单,包括客户的 id(主键)。

$res = new \App\Customer;

过滤不是主键的列时,一切正常:

>>> $res = \App\Customer::where('customer_name', 'like', "%frank%")->first();
=> App\Customer {#736}
>>> $res = \App\Customer::where('customer_name', 'like', "%frank%")->paginate(15)->first();
=> App\Customer {#749}

但是,过滤主键然后调用会paginate()返回一个空集合。

>>> $res = \App\Customer::where('id', 3)->first();
=> App\Customer {#669}
>>> $res = \App\Customer::where('id', 3)->paginate(15)->first();
=> null

simplePaginate()工作正常,但是我想使用完整的附加功能paginate()

(是的,我知道在过滤主键时我只会得到一条记录,但是如果不调用paginate()集合,我的视图会因为它使用分页方法而中断,例如firstItem(), lastItem(),total()等)

4

2 回答 2

0

我不确定它为什么会起作用,但是将我的 where 移到 Model 的范围方法中解决了这个问题。

于 2016-08-29T21:09:54.460 回答
0

尝试:

$res = \App\Customer::where('id', 3)->paginate(15);

于 2016-08-29T19:24:16.307 回答