[英]Laravel WhereIn Not Working
为什么这会按预期返回集合?
$postcodes = DB::table('payments')->whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
print_r($postcodes);
但这会返回错误;
$payments = Payment::all();
$payments->whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
print_r($payments);
错误是;
Call to undefined method Illuminate\Database\Eloquent\Collection::whereIn()
我当然有一个付款模型。
<?php namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Payment extends Model {
//
}
无需在whereIn()
之前调用all()
whereIn()
。 将代码更改为此:
$payments = Payment::whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
您可以在Eloquent基本用法文档中找到更多示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.