为什么这会按预期返回集合;
$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 {
//
}
答案 0 :(得分:2)
无需在all()
之前致电whereIn()
。将您的代码更改为:
$payments = Payment::whereIn('VendorZIP', array('BS19AA','PO48AA'))->get();
您可以在Eloquent basic usage文档中找到更多示例。