Explorar o código

Update company - select Countries e Cities dinamico

ferrari hai 3 meses
pai
achega
de859e900b
Modificáronse 2 ficheiros con 13 adicións e 8 borrados
  1. 7 0
      app/Livewire/Company.php
  2. 6 8
      resources/views/livewire/company.blade.php

+ 7 - 0
app/Livewire/Company.php

@@ -2,6 +2,8 @@
 
 namespace App\Livewire;
 
+use App\Models\City;
+use App\Models\Country;
 use Livewire\Component;
 use Livewire\Attributes\Validate;
 
@@ -29,10 +31,15 @@ class Company extends Component
 
     public $current_company = null;
 
+    public $cities = [];    
+    public $countries = [];    
+
     public $is_edit = false;
 
     public function render()
     {
+        $this->cities = City::all();
+        $this->countries = Country::all();
 
         // Get Company
         $this->current_company = \App\Models\Company::first();

+ 6 - 8
resources/views/livewire/company.blade.php

@@ -99,10 +99,9 @@
                     <label for="city_id">Città</label>
                     <select class="form-select @error('city_id') is-invalid @enderror" id="city_id" name="city_id" required>
                         <option value="" @if (!$city_id) selected @endif disabled>Seleziona</option>
-                        {{-- @foreach ($cities as $city)
-                        <option value="{{$city->id}}" @if ($city_id==$city->id) selected @endif>{{$city->name}}</option>
-                        @endforeach --}}
-                        <option value="city_1">city_1</option>
+                        @foreach ($cities as $city)
+                        <option value="{{$city->id}}" @if ($city_id == $city->id) selected @endif>{{$city->name}}</option>
+                        @endforeach
                     </select>
                     @error('city_id')
                     <div class="invalid-feedback">{{ $message }}</div>
@@ -114,10 +113,9 @@
                     <label for="country_id">Stato</label>
                     <select class="form-select @error('country_id') is-invalid @enderror" id="country_id" name="country_id" required>
                         <option value="" @if (!$country_id) selected @endif disabled>Seleziona</option>
-                        {{-- @foreach ($countries as $country)
-                        <option value="{{$country->id}}" @if ($country_id==$country->id) selected @endif>{{$country->name}}</option>
-                        @endforeach --}}
-                        <option value="country_1">country_1</option>
+                        @foreach ($countries as $country)
+                        <option value="{{$country->id}}" @if ($country_id == $country->id) selected @endif>{{$country->name}}</option>
+                        @endforeach
                     </select>
                     @error('country_id')
                     <div class="invalid-feedback">{{ $message }}</div>