gpt4 book ai didi

php - array_key_exists() 异常错误,为什么不处理 false?

转载 作者:行者123 更新时间:2023-12-05 04:06:19 24 4
gpt4 key购买 nike

我得到了这个错误。当在 CREATED_ATUPDATED_AT 上使用这种模型执行初始化错误时,我得到了 array_key_exists() 的错误,但是当我初始化时null 值我的模型正常工作.. 谁能解释我为什么会出现这种行为?
我正在使用 Laravel 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 字段时

关于php - array_key_exists() 异常错误,为什么不处理 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49934640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com