samedi 1 décembre 2018

Mass Assignment issue with `updateOrCreate` in Laravel, why?

I have a very simple model:

class Employee extends \Eloquent
{
}

And what I would like to do is to synchronize the local data with the ones stored in a remote server. In my MySQL I have

PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)

So I am sure that if I match on id, I would never do mass assignment.

So when I do:

foreach((new RemoteEmployee())->all() as $emp) {
    Employee::updateOrCreate(['id' => $emp['id']], [
        'firstname' => $emp['id'], 
        'lastname' => $emp['lastname'], 
        'phone' => $emp['phone']
    ]);
}

I should not get this error:

Add [id] to fillable property to allow mass assignment on [App\Models\Employee].

Anyway, if I modify my model as follow:

class Employee extends \Eloquent
{
    protected $fillable = ['*'];
}

I do not get any errors, but my entries are null.

Why?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FST5XL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire