[英]Laravel WhereIn Not Working
Why does this return a collection as expected; 为什么这会按预期返回集合?
$postcodes = DB::table('payments')->whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
print_r($postcodes);
But this returns an error; 但这会返回错误;
$payments = Payment::all();
$payments->whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
print_r($payments);
The error is; 错误是;
Call to undefined method Illuminate\Database\Eloquent\Collection::whereIn()
Of course I have a Payment model; 我当然有一个付款模型。
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model {
//
}
There's no need to call all()
before whereIn()
. 无需在whereIn()
之前调用all()
whereIn()
。 Change your code to this: 将代码更改为此:
$payments = Payment::whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
You can find more examples in Eloquent basic usage documentation. 您可以在Eloquent基本用法文档中找到更多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.