defaultKeys as $key) { $extraValue = []; $defaultValues = [ 'restaurant_name' => $extraValue, ]; $setting = Setting::where('restaurant_id', $restaurant->id) ->where('key', $key) ->first(); if (! $setting) { // Create if it doesn't exist Setting::create([ 'restaurant_id' => $restaurant->id, 'key' => $key, 'value' => $defaultValues[$key] ?? null, 'type' => 'vendor', 'is_active' => true, ]); $this->info("Added missing setting '{$key}' for Restaurant ID: {$restaurant->id}"); } elseif (is_null($setting->value)) { // Update only if value is NULL if (array_key_exists($key, $defaultValues)) { $setting->update(['value' => $defaultValues[$key]]); $this->info("Updated '{$key}' for Restaurant ID: {$restaurant->id} because value was null"); } } else { // Skip if already exists with a non-null value $this->line("Setting '{$key}' already exists for Restaurant ID: {$restaurant->id} with non-null value — skipped."); } } } $this->info('All settings sync complete.'); } }