# Manual Edits for grocery-api

Apply these changes locally (some files could not be written from the tooling).

---

## 1. Fix admin/settings update

**File:** `app/Http/Controllers/Admin/SettingsController.php`

Replace the `update` method and add the `$settingKeys` property so the form's flat fields (store_name, store_email, etc.) are saved correctly.

- Add this property after the opening of the class (after `{`):

```php
/** Keys allowed from the settings form and their type/group (matches view and seeder). */
protected array $settingKeys = [
    'store_name' => ['type' => 'text', 'group' => 'store'],
    'store_email' => ['type' => 'text', 'group' => 'store'],
    'store_phone' => ['type' => 'text', 'group' => 'store'],
    'store_address' => ['type' => 'text', 'group' => 'store'],
    'currency' => ['type' => 'text', 'group' => 'tax'],
    'currency_symbol' => ['type' => 'text', 'group' => 'tax'],
    'default_tax_rate' => ['type' => 'number', 'group' => 'tax'],
    'delivery_charge' => ['type' => 'number', 'group' => 'delivery'],
    'free_delivery_threshold' => ['type' => 'number', 'group' => 'delivery'],
    'order_cancellation_hours' => ['type' => 'number', 'group' => 'order'],
    'auto_confirm_orders' => ['type' => 'boolean', 'group' => 'order'],
];
```

- Replace the entire `update` method with:

```php
public function update(Request $request)
{
    foreach ($this->settingKeys as $key => $config) {
        $value = $request->input($key);

        if ($config['type'] === 'boolean') {
            $value = $request->has($key) && in_array($value, ['1', 1, true, 'true'], true) ? 'true' : 'false';
        }

        if ($value !== null && $value !== '') {
            Setting::set($key, $value ?? '', $config['type'], $config['group']);
        }
    }

    return redirect()->route('admin.settings.index')
        ->with('success', 'Settings updated successfully.');
}
```

---

## 2. Add Sliders to admin routes and sidebar

**File:** `routes/admin.php`

- After the line `use App\Http\Controllers\Admin\SettingsController;` add:
  `use App\Http\Controllers\Admin\SliderController;`
- Inside the protected admin group, after `Route::resource('pages', PageController::class);` add a new line:
  `Route::resource('sliders', SliderController::class);`

**File:** `resources/views/admin/partials/sidebar.blade.php`

- In the "Content" section, **before** the "Pages" `<li>`, add this `<li>`:
```html
<li>
    <a href="{{ route('admin.sliders.index') }}" class="flex items-center px-4 py-2 rounded hover:bg-gray-700 {{ request()->routeIs('admin.sliders.*') ? 'bg-gray-700' : '' }}">
        <i class="fas fa-images w-5 mr-3"></i>
        Sliders
    </a>
</li>
```

---

## 3. Add public API route for sliders

**File:** `routes/api.php`

- After `use App\Http\Controllers\Api\V1\ProductController;` add:
  `use App\Http\Controllers\Api\V1\SliderController;`
- Under "Public routes" (after the products routes), add:
  `Route::get('/sliders', [SliderController::class, 'index']);`

---

## 4. Run migration for sliders

```bash
cd grocery-api
php artisan migrate
```

---

Slider model, API controller, resource, admin controller, migration and views are already created in the repo.
