doutu9810 2018-04-20 05:32 采纳率: 0%
浏览 1469
已采纳

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

I got this error .. When executing with this kind of model initialize false on CREATED_AT and UPDATED_AT i got the error of array_key_exists() , but when i initialize with null values mine model working correctly .. Can anybody explain me why i got this kind of behavior ?
I am using Laravel 5.6 version ..

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| 

Model:

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条回答 默认 最新

  • dongtan2603 2018-04-20 05:35
    关注

    use

    public $timestamps = false;
    

    when you don't want created_at and updated_at fields

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料