#updateOrCreate is not working as expected

7 messages ยท Page 1 of 1 (latest)

rugged spear
#

Hi

I'm trying to use updateOrCreate on a model

input data

$result = [
  "id" => 9150
  "name" => "lemon"
  "image" => "lemon.png"
]

code

$ing = Ingredient::updateOrCreate([
    'name' => $result['name'],
    ],
    [
        'external_id' => $result['id'],
        'image' => $result['image']
    ]);

                    dd($ing);

the property 'external_id' is set, but the property 'image' is not and I cannot figure out what I'm missing

cunning furnace
#

I don't remember exactly but I think updateOrCreate is making a bulk update so your fields have to be mass updatable

rugged spear
#

You are absolutely right... I have forgotten to update the $fillable - thanks!

glass sonnet
#

I assume this can be marked as solved? ๐Ÿ™‚

rugged spear
#

hmm--- looking for the 'solved button'

glass sonnet
#

It's just a tag, added the solved tag just now ๐Ÿ™‚