normykinz's avatar

updateOrCreate array merge problem

Not sure what's going on here but the updateOrCreate method doesn't seem to merge the two arrays.

Am I missing something obvious here?

public function updatedProperties(bool $value, string $key): void
{
    $index = (int) Str::of($key)->explode('.')->first();
    $property = $this->properties->get($index);

    $upsert = [
        'visibility_id' => $property->id,
        'visibility_type' => VisibilityTypes::PROPERTY,
    ];

    GlobalVisibility::updateOrCreate($upsert, ['is_visible' => $value]);
}
SQLSTATE[HY000]: General error: 1364 Field 'visibility_id' doesn't have a default value (Connection: lvr, SQL: insert into `global_visibilities` (`is_visible`, `updated_at`, `created_at`) values (0, 2023-06-02 10:16:08, 2023-06-02 10:16:08))
0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

Are visibility_id and visibility_type fillable attributes on the Model?

normykinz's avatar

@tykus It would help if I spelled 'visibility' correctly in the $fillable array.

D-OH!

1 like

Please or to participate in this conversation.