GOOD SHELL MAS BOY
Server: Apache/2.4.52 (Ubuntu)
System: Linux vmi1836763.contaboserver.net 5.15.0-130-generic #140-Ubuntu SMP Wed Dec 18 17:59:53 UTC 2024 x86_64
User: www-data (33)
PHP: 8.4.10
Disabled: NONE
Upload Files
File: /var/www/admin.fixgini.com/app/Livewire/City/Store.php
<?php

namespace App\Livewire\City;

use App\Models\City;
use App\Models\Country;
use App\Models\State;
use Livewire\Component;

class Store extends Component
{
    public $name;
    public $country_id;
    public $state_id;

    protected $rules = [
        'name' => 'required|string|unique:states,name',
        'state_id' => 'required|string|exists:states,id',
        'country_id' => 'required|string|exists:countries,id',
    ];
    public function saveCity()
    {
        $this->validate();
        try {
            City::create([
                'name' => $this->name,
                'state_id' => $this->state_id,
                'country_id' => $this->country_id,
            ]);
            session()->flash('status', 'Saved.');
            return redirect()->to('/location');
        } catch (\Throwable $th) {
            $this->addError('name', $th->getMessage());
        }
    }


    public function render()
    {
        return view('livewire.city.store', [
            'countries' => Country::orderBy('name')->get(),
            'states' => State::orderBy('name')->get(),
        ]);
    }
}