country = request()->route('country', config('app.domain_country')); $this->country_id = Country::query() ->where('code', $this->country) ->value('id'); } public function createCity(): void { $validated = $this->validate([ 'name' => ['required', 'string', 'max:255', 'unique:cities,name'], 'country_id' => ['required', 'exists:countries,id'], 'latitude' => ['required', 'numeric', 'between:-90,90'], 'longitude' => ['required', 'numeric', 'between:-180,180'], 'population' => ['nullable', 'integer', 'min:0'], 'population_date' => ['nullable', 'string', 'max:255'], ]); $validated['slug'] = str($validated['name'])->slug(); $validated['created_by'] = auth()->id(); $city = City::create($validated); session()->flash('status', __('City successfully created!')); $this->redirect(route_with_country('cities.index'), navigate: true); } public function with(): array { return [ 'countries' => Country::query()->orderBy('name')->get(), ]; } }; ?>