@section('scripts')
<script type="text/javascript">
$("#country").change(function(){
$.ajax({
url: "{{ route('admin.cities.get_by_country') }}?country_id=" + $(this).val(),
method: 'GET',
success: function(data) {
$('#city').html(data.html);
}
});
});
</script>
@endsection
public function get_by_country(Request $request)
{
abort_unless(Gate::allows('city_access'), 401);
if (!$request->country_id) {
$html = '<option value="">'.trans('global.pleaseSelect').'</option>';
} else {
$html = '';
$cities = City::where('country_id', $request->country_id)->get();
foreach ($cities as $city) {
$html .= '<option value="'.$city->id.'">'.$city->name.'</option>';
}
}
return response()->json(['html' => $html]);
}