Reputation: 626
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'
];
}
Upvotes: 3
Views: 6195
Reputation:
use
public $timestamps = false;
when you don't want created_at and updated_at fields
Upvotes: 3