我正在为客户创建一个允许多个选项的搜索表单,包括客户的 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()
等)