File: //home/armgroup/libs/resources/views/account/address/edit.blade.php
@extends('layouts.app')
@section('content')
<div class="container my-5 body-content">
<div class="row">
<div class="col-lg-3 col-sm-12">
@include('account.sidebar')
</div>
<div class="col-lg-9 col-sm-12">
<div class="card">
<h5 class="card-header">{{ __('Edit Address') }}</h5>
<div class="card-body">
@include('layouts.errors')
<form action="{{ route('account.addresses.update', $address->id) }}" method="POST">
@csrf
@method('patch')
@if(request()->has('_back'))
<input type="hidden" name="_back" value="addresses">
@endif
<div class="row">
<div class="form-group col-md-6 mb-3">
<label for="name">نام و نامخانوادگی گیرنده *</label>
<input name="name" type="text" class="form-control" id="name" autofocus
value="{{ old('name', $address->name) }}">
</div>
<div class="form-group col-md-6 mb-3">
<label for="mobile">{{ __('Mobile') }} *</label>
<input type="text" name="mobile" class="form-control" id="mobile" dir="ltr"
value="{{ old('mobile', $address->mobile) }}">
</div>
<div class="form-group col-md-6 mb-3">
<label for="province_id">{{ __('Province') }} *</label>
<select name="province_id" class="form-control form-select" id="province_id">
<option value="">{{ __('Please select') }}</option>
@foreach($provinces as $province)
<option value="{{ $province->id }}"
{{ old('province_id', $address->city->province_id) == $province->id ? 'selected' : '' }}>
{{ $province->name }}
</option>
@endforeach
</select>
</div>
<div class="form-group col-md-6 mb-3">
<label for="city_id">{{ __('City') }} *</label>
<select name="city_id" class="form-control form-select" id="city_id">
<option value="">{{ __('Select the province first') }}</option>
</select>
</div>
<div class="form-group col-md-6 mb-3">
<label for="national_code">{{ __('National Code') }}</label>
<input name="national_code" type="text" class="form-control" id="national_code" dir="ltr"
value="{{ old('national_code', $address->national_code) }}">
</div>
<div class="form-group col-md-6 mb-3">
<label for="postal_code">{{ __('Postal Code') }} *</label>
<input name="postal_code" type="text" class="form-control" id="postal_code" dir="ltr"
value="{{ old('postal_code', $address->postal_code) }}">
</div>
<div class="form-group col-md-6 mb-3">
<label for="plaque">{{ __('Plaque') }}</label>
<input name="plaque" type="text" class="form-control" id="plaque" dir="ltr"
value="{{ old('plaque', $address->plaque) }}">
</div>
<div class="form-group col-md-6 mb-3">
<label for="floor">{{ __('Floor') }}</label>
<input name="floor" type="text" class="form-control" id="floor" dir="ltr"
value="{{ old('floor', $address->floor) }}">
</div>
<div class="form-group col-md-12 mb-3">
<label for="address">{{ __('Address') }} *</label>
<input name="address" type="text" class="form-control" id="address"
value="{{ old('address', $address->address) }}">
</div>
<div class="form-group col-md-12 mb-3">
<label for="address">{{ __('Location') }}</label>
<input type="hidden" id="lat" name="lat" value="{{ old('lat', $address->lat) }}">
<input type="hidden" id="lng" name="lng" value="{{ old('lng', $address->lng) }}">
<div id="map" style="height: 300px; width: inherit;"></div>
@unless(old('lat', $address->lat) && old('lng', $address->lng))
<small>* {{ __('Click on the map to display the marker') }}</small>
@endunless
</div>
</div>
<div>
<button type="submit" class="btn btn-primary">{{ __('Save') }}</button>
<a href="{{ request()->has('_back') ? route('addresses.index') : route('account.addresses.index') }}"
class="btn btn-danger float-end">
{{ __('Cancel') }}
</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('header')
<link rel="stylesheet" href="{{ asset('leaflet/leaflet.css') }}" />
<link rel="stylesheet" href="{{ asset('Leaflet.EasyButton/src/easy-button.css') }}">
@endsection
@section('footer')
<script src="{{ asset('leaflet/leaflet.js') }}"></script>
<script src="{{ asset('Leaflet.EasyButton/src/easy-button.js') }}"></script>
<script>
var default_lat = `{{ old("lat", $address->lat) }}` ? `{{ old("lat", $address->lat) }}` : `{{ config('leaflet.default_lat') }}`;
var default_lng = `{{ old("lng", $address->lng) }}` ? `{{ old("lng", $address->lng) }}` : `{{ config('leaflet.default_lng') }}`;
var map = L.map('map').setView([default_lat, default_lng], 13);
map.scrollWheelZoom.disable()
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '',
maxZoom: 18,
tileSize: 512,
zoomOffset: -1,
}).addTo(map);
L.easyButton( 'fa-search-location', function(){
map.locate();
}).addTo(map);
var icon = new L.Icon.Default();
icon.options.shadowSize = [0,0];
var marker = L.marker([default_lat, default_lng],{
draggable: true,
icon : icon
});
map.on('click', function(e){
updatePoints(e.latlng.lat,e.latlng.lng)
});
marker.on('moveend', function(e){
updatePoints(e.target._latlng.lat,e.target._latlng.lng)
});
if(`{{ old("lat", $address->lat) }}` && `{{ old("lng", $address->lng) }}`) {
marker.setLatLng([default_lat, default_lng]).addTo(map);
} else {
// map.locate();
}
function updatePoints(lat, lng) {
$('#lat').val(lat);
$('#lng').val(lng);
map.setView([lat, lng]);
marker.setLatLng([lat,lng]).addTo(map);
}
map.on('locationfound', onLocationFound);
function onLocationFound(e) {
updatePoints(e.latlng.lat, e.latlng.lng);
}
map.on('locationerror', onLocationError);
function onLocationError(e) {
iziToast.error({
message: "شما دسترسی ما به GPS را محدود کردهاید، برای مکانیابی خودکار باید GPS را فعال کرده و دسترسی لازم را بدهید.",
'position': 'topLeft'
});
if($('#lat').val() && $('#lng').val())
updatePoints($('#lat').val(), $('#lng').val());
}
</script>
<script>
$('#province_id').on('change', function() {
var select = $('#city_id');
$('option', select).remove();
if(this.value == "") {
select.append("<option value=\"\">{{ __('Select the province first') }}</option>");
return;
}
else
url = `{{ url('/province') }}` + '/' + this.value;
$.ajax(url,
{
success: function (data) {
select.append("<option value=\"\">{{ __('Please select') }}</option>");
for(let i=0 ; i<data.length; i++) {
select.append(`<option value="${data[i].id}">${data[i].name}</option>`);
}
},
error: function (jqXhr, textStatus, errorMessage) {
alert('Error: ' + errorMessage);
}
});
});
$( document ).ready(function() {
@if(old('city_id', $address->city->id))
var select = $('#city_id');
$('option', select).remove();
url = `{{ url('/province') }}` + '/' + `{{ old('province_id', $address->city->province_id) }}`;
$.ajax(url,
{
success: function (data) {
city_id = `{{ old('city_id', $address->city->id) }}`;
select.append("<option value=\"\">{{ __('Please select') }}</option>");
for(let i=0 ; i<data.length; i++) {
select.append(`<option value="${data[i].id}" `+ (data[i].id == city_id ? "selected" : "") + `>${data[i].name}</option>`);
}
},
error: function (jqXhr, textStatus, errorMessage) {
alert('Error: ' + errorMessage);
}
});
@endif
})
</script>
@endsection