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

时间:2018-04-20 05:32:34

标签: php laravel

我收到了这个错误..当使用这种模型执行时CREATED_ATUPDATED_AT初始化为false我得到了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'
    ];
}

1 个答案:

答案 0 :(得分:3)

使用

public $timestamps = false;

当您不想要created_at和updated_at字段