zizohassan / laraflat

Advanced laravel system to build admin panel
http://laraflat.com
MIT License
150 stars 76 forks source link

Send ajax request with city id to get region #116

Open ehabfoad opened 6 years ago

ehabfoad commented 6 years ago

السؤال بخصوص ربط ال الدول بالمدن بحيث تظهر عن اختيار الدولة المدن الخاص بها

نفذت نفس الفكرة المعمولة فى الفيديو ده Laravel 5.4 Larafalt Send ajax request with country id to get state لا تعمل معى انا استخدم laraflat 3 حاولت استخدام طريقة اسهل بالكود المرفق data-secid in region مش بيجى جواها الid صح

<script type="text/javascript">
    window.onload = function() {
    var sections = document.querySelector(".sections");
    sections.onchange = function () {
        var secId = this.value;
        var s_Sections = document.querySelectorAll(".subsection>option");
        var x = 0;
        while (x < s_Sections.length) {
            if(s_Sections[x].dataset.secid == secId){
                s_Sections[x].classList.add("active");
            }
            else{
                s_Sections[x].classList.remove("active");
            }
            x++;
        }
        document.querySelectorAll(".subsection>option[data-secid="+secId+"]")[0].setAttribute("selected",true);
    }
}
</script>

<div class="col-sm-3">
<div class="form-group {{ $errors->has("city") ? "has-error" : "" }}">
<label for="city">{{ trans( "city.city") }}</label>
    @php $cities = App\Application\Model\City::pluck("title" ,"id")->all()  @endphp
    @php  $city_id = isset($item) ? $item->city_id : null @endphp
    <select name="city_id "  class="form-control sections" id="city" > 
    @foreach( $cities as $key => $relatedItem)
  <option value="{{ $key }}"  {{ $key == $city_id  ? "selected" : "" }}> {{ is_json($relatedItem) ? getDefaultValueKey($relatedItem) :  $relatedItem}}</option>
    @endforeach
</select>
    @if ($errors->has("city"))
    <div class="alert alert-danger">
<span class="help-block">
    <strong>{{ $errors->first("city") }}</strong>
    </span>
    </div>
    @endif
    </div>

 </div>
   <div class="col-sm-3">
   <div class="form-group {{ $errors->has("region") ? "has-error" : "" }}">
 <label for="region">{{ trans( "region.region") }}</label>
   @php $regions = App\Application\Model\Region::pluck("title" ,"id")->all()  @endphp
     @php  $region_id = isset($item) ? $item->region_id : null @endphp
   @php  $city_id = isset($item) ? $item->city_id : null @endphp

  <select name="region_id "  class="form-control subsection" id="regions">

   @foreach( $regions as $keys => $relatedItem )
  <option value="{{ $keys }}"  {{ $keys == $region_id   }} data-secid="{{ $key }}" {{ $key == $city_id  }}> {{ is_json($relatedItem) ? getDefaultValueKey($relatedItem) :  $relatedItem}}</option> 

 @endforeach
</select>
 @if ($errors->has("region"))
 <div class="alert alert-danger">
<span class="help-block">
   <strong>{{ $errors->first("region") }}</strong>
   </span>
   </div>
 @endif
</div>

 </div>
FoushWare commented 6 years ago

سؤال بس . هل حليت مشكلة انك تضيف new method like getUser() to the controller and get permission to use it لاني مش عارف اعملها الصراحة @ehabfoad

ehabfoad commented 6 years ago

مع الاسف لسه محلتش المشكلة @AhmedFouad60 @zizohassan