git add .

git commit "fix: city selection, comment user display, and back button bug"
This commit is contained in:
2026-08-22 09:13:09 +03:30
parent 669dd7cfff
commit 947d2425d9
16 changed files with 114 additions and 63 deletions
+5 -2
View File
@@ -3,11 +3,14 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Models\City; use App\Models\City;
use App\Models\Province;
class CityController extends Controller class CityController extends Controller
{ {
public function byProvince($province) public function byProvince( Province $province)
{ {
return City::where('province_id', $province)->get(); return response()->json(
$province->cities()->select('id', 'name')->get()
);
} }
} }
+1 -1
View File
@@ -34,7 +34,7 @@ class Province extends Model
} }
public function cities() public function cities()
{ {
return $this->belongsTo(City::class); return $this->hasMany(City::class);
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

@@ -34,7 +34,13 @@
<div class="comment-header"> <div class="comment-header">
<div> <div>
<h4> <h4>
@if($comment->tour_id)
{{ $comment->tour->title ?? 'مورد حذف شده' }} {{ $comment->tour->title ?? 'مورد حذف شده' }}
@elseif($comment->flight_id)
{{ $comment->flight->airline ?? 'مورد حذف شده' }}
@else
مورد حذف شده
@endif
</h4> </h4>
<span> <span>
{{ $comment->created_at->format('Y/m/d') }} {{ $comment->created_at->format('Y/m/d') }}
@@ -35,7 +35,11 @@
@if($favorite->favoritable_type == 'App\Models\Tour') @if($favorite->favoritable_type == 'App\Models\Tour')
<h3> <h3>
{{ $favorite->favoritable?->title ?? 'مورد حذف شده' }} </h3> {{ $favorite->favoritable?->title ?? 'مورد حذف شده' }}
</h3>
<h3>
{{ $favorite->favoritable?->summary ?? 'مورد حذف شده' }}
</h3>
<p> <p>
تور تور
@@ -44,7 +48,10 @@
@elseif($favorite->favoritable_type == 'App\Models\Flight') @elseif($favorite->favoritable_type == 'App\Models\Flight')
<h3> <h3>
{{ $favorite->favoritable->name }} {{ $favorite->favoritable->airline }}
</h3>
<h3>
{{ $favorite->favoritable->flight_number }}
</h3> </h3>
<p> <p>
@@ -632,9 +632,8 @@
.append('<option value="">در حال دریافت شهرها...</option>'); .append('<option value="">در حال دریافت شهرها...</option>');
$.ajax({ $.ajax({
url: "{{ route('users.cities.province', ':province') }}" url: "{{ route('cities.province', ':province') }}"
.replace(':province', provinceId), .replace(':province', provinceId),
type: 'GET', type: 'GET',
success: function (cities) { success: function (cities) {
@@ -660,13 +659,9 @@
}, },
error: function () { error: function () {
citySelect.empty(); citySelect.empty();
citySelect.append('<option value="">خطا در دریافت شهرها</option>');
citySelect.append( citySelect.prop('disabled', false);
'<option value="">خطا در دریافت شهرها</option>'
);
} }
}); });
+37
View File
@@ -570,5 +570,42 @@
</div> </div>
</div> </div>
<script>
document.addEventListener('DOMContentLoaded', function () {
const provinceSelect = document.getElementById('province_id');
const citySelect = document.getElementById('city_id');
provinceSelect.addEventListener('change', function () {
const provinceId = this.value;
citySelect.innerHTML = '<option value="">در حال بارگذاری...</option>';
citySelect.disabled = true;
if (!provinceId) {
citySelect.innerHTML = '<option value="">ابتدا استان را انتخاب کنید</option>';
return;
}
fetch(`{{ url('/cities') }}/${provinceId}`)
.then(response => response.json())
.then(cities => {
citySelect.innerHTML = '<option value="">انتخاب شهرستان</option>';
cities.forEach(city => {
const option = document.createElement('option');
option.value = city.id;
option.textContent = city.name;
citySelect.appendChild(option);
});
citySelect.disabled = false;
})
.catch(() => {
citySelect.innerHTML = '<option value="">خطا در دریافت شهرها</option>';
citySelect.disabled = false;
});
});
});
</script>
@endsection @endsection
+1 -1
View File
@@ -166,7 +166,7 @@
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<strong> <strong>
{{ $comment->user->name }} {{ $comment->user ? $comment->user->first_name . ' ' . $comment->user->last_name : 'کاربر مهمان' }}
</strong> </strong>
<small> <small>
+4
View File
@@ -20,6 +20,8 @@
@includeUnless(isset($withoutHero),'layouts.hero') @includeUnless(isset($withoutHero),'layouts.hero')
@yield('content') @yield('content')
@includeUnless(isset($withoutFooter),'layouts.footer') @includeUnless(isset($withoutFooter),'layouts.footer')
<script src="{{asset('assets/js/jquery-3.7.1.min.js')}}"></script>
<script src="{{asset('assets/js/moment.js')}}"></script> <script src="{{asset('assets/js/moment.js')}}"></script>
<script src="{{asset('assets/js/bootstrap.js')}}"></script> <script src="{{asset('assets/js/bootstrap.js')}}"></script>
<script src="{{asset('assets/js/owl-carousel.js')}}"></script> <script src="{{asset('assets/js/owl-carousel.js')}}"></script>
@@ -41,5 +43,7 @@
<script src="{{asset('assets/js/custom.js')}}"></script> <script src="{{asset('assets/js/custom.js')}}"></script>
<script async="" defer="" src="{{asset('assets/js/js.js')}}"></script> <script async="" defer="" src="{{asset('assets/js/js.js')}}"></script>
@stack('scripts')
</body> </body>
</html> </html>
+8 -8
View File
@@ -61,14 +61,6 @@
</strong> </strong>
<a
href="{{ route('index') }}"
class="btn btn-outline-primary rounded-pill px-4"
>
برگشت
</a>
</div> </div>
</div> </div>
@@ -81,6 +73,14 @@
</div> </div>
<div class="mt-4 d-flex justify-content-center">
<a
href="{{ route('index') }}"
class="btn btn-outline-primary rounded-pill px-4"
>
برگشت
</a>
</div>
<div class="mt-5 d-flex justify-content-center"> <div class="mt-5 d-flex justify-content-center">
+1 -1
View File
@@ -200,7 +200,7 @@
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<strong> <strong>
{{ $comment->user?->name ?? 'کاربر مهمان' }} {{ $comment->user ? $comment->user->first_name . ' ' . $comment->user->last_name : 'کاربر مهمان' }}
</strong> </strong>
+2 -3
View File
@@ -23,6 +23,8 @@ Route::get('/tours/{tour}', [TourController::class, 'show'])->name('tours.show')
Route::get('/comments',[CommentController::class,'index'])->name('comments.index'); Route::get('/comments',[CommentController::class,'index'])->name('comments.index');
Route::post('/comments',[CommentController::class,'store'])->name('comments.store'); Route::post('/comments',[CommentController::class,'store'])->name('comments.store');
Route::get('/cities/{province}', [CityController::class, 'byProvince'])->name('cities.province');
Route::prefix('users')->name('users.')->middleware('auth:web')->group(function (){ Route::prefix('users')->name('users.')->middleware('auth:web')->group(function (){
Route::get('/',[DashboardController::class,'index'])->name('dashboard'); Route::get('/',[DashboardController::class,'index'])->name('dashboard');
@@ -37,9 +39,6 @@ Route::prefix('users')->name('users.')->middleware('auth:web')->group(function (
Route::delete('/favorite/{favorite}',[FavoriteController::class,'destroy'])->name('favorite.destroy'); Route::delete('/favorite/{favorite}',[FavoriteController::class,'destroy'])->name('favorite.destroy');
Route::get('/cities/{province}', [CityController::class, 'byProvince'])->name('cities.province');
Route::get('/reservations', [ReservationController::class, 'index'])->name('reservations.index'); Route::get('/reservations', [ReservationController::class, 'index'])->name('reservations.index');
Route::post('/reservations', [ReservationController::class, 'store'])->name('reservations.store'); Route::post('/reservations', [ReservationController::class, 'store'])->name('reservations.store');