我得到了这个错误..使用这种模型执行时,CREATED_AT
和UPDATED_AT
上初始化false,我得到了array_key_exists((的错误,但是当我使用空值初始化时,我的模型正常工作..谁能解释我为什么会有这种行为?
我正在使用拉拉维尔5.6版本..
Seeding: CouponTableSeeder
ErrorException : array_key_exists(): The first argument should be either a string or an integer
at /Applications/XAMPP/xamppfiles/htdocs/sites/FakeProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:1028
1024| // Here we will spin through every attribute and see if this is in the array of
1025| // dirty attributes. If it is, we will return true and if we make it through
1026| // all of the attributes for the entire array we will return false at end.
1027| foreach (Arr::wrap($attributes) as $attribute) {
> 1028| if (array_key_exists($attribute, $changes)) {
1029| return true;
1030| }
1031|
}
1032|
型:
class Coupon extends Model
{
protected $table = 'coupons';
protected $primaryKey = 'coupon_id';
public $incrementing = false;
const CREATED_AT = false;
const UPDATED_AT = false;
protected $fillable = [
'coupon_id','title','amount','price','type','created_at','expired_at'
];
}
使用
public $timestamps = false;
当您不需要created_at和updated_at字段时