diff --git a/app/Http/Controllers/admin/CityController.php b/app/Http/Controllers/admin/CityController.php new file mode 100644 index 0000000..bc589f4 --- /dev/null +++ b/app/Http/Controllers/admin/CityController.php @@ -0,0 +1,55 @@ +filled('province_id')) { + $query->where('province_id', $request->province_id); + } + $cities = $query->paginate(20); + $provinces = Province::all(); + return view('admin.cities.index', compact('cities', 'provinces')); + } + + public function create() + { + $provinces = Province::all(); + return view('admin.cities.create', compact('provinces')); + } + + // استفاده از CityRequest به جای Request + public function store(CityStoreRequest $request) + { + City::create($request->validated()); + return redirect()->route('admin.locations.cities.index')->with('success', 'شهر با موفقیت ایجاد شد.'); + } + + public function edit(City $city) + { + $provinces = Province::all(); + return view('admin.cities.edit', compact('city', 'provinces')); + } + + public function update(CityUpdateRequest $request, City $city) + { + $city->update($request->validated()); + return redirect()->route('admin.locations.cities.index')->with('success', 'شهر ویرایش شد.'); + } + + public function destroy(City $city) + { + $city->delete(); + return back()->with('success', 'شهر حذف شد.'); + } +} diff --git a/app/Http/Controllers/admin/ProvinceController.php b/app/Http/Controllers/admin/ProvinceController.php new file mode 100644 index 0000000..bf755f1 --- /dev/null +++ b/app/Http/Controllers/admin/ProvinceController.php @@ -0,0 +1,45 @@ +validated()); + return redirect()->route('admin.locations.provinces.index')->with('success', 'استان با موفقیت ایجاد شد.'); + } + + public function edit(Province $province) + { + return view('admin.provinces.edit', compact('province')); + } + + public function update(ProvinceUpdateRequest $request, Province $province) + { + $province->update($request->validated()); + return redirect()->route('admin.locations.provinces.index')->with('success', 'استان ویرایش شد.'); + } + + public function destroy(Province $province) + { + $province->delete(); + return back()->with('success', 'استان حذف شد.'); + } +} diff --git a/app/Http/Requests/CityStoreRequest.php b/app/Http/Requests/CityStoreRequest.php new file mode 100644 index 0000000..3b40945 --- /dev/null +++ b/app/Http/Requests/CityStoreRequest.php @@ -0,0 +1,39 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => + [ + 'required', + 'string', + 'max:100' + ], + 'province_id' => + [ + 'required', + 'exists:provinces,id' + ], + ]; + } +} diff --git a/app/Http/Requests/ProvinceUpdateRequest.php b/app/Http/Requests/ProvinceUpdateRequest.php new file mode 100644 index 0000000..6dc2f09 --- /dev/null +++ b/app/Http/Requests/ProvinceUpdateRequest.php @@ -0,0 +1,37 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => + [ + 'required', + 'string', + 'max:100' + ], + + + ]; + } +} diff --git a/resources/views/admin/cities/create.blade.php b/resources/views/admin/cities/create.blade.php new file mode 100644 index 0000000..6da17f0 --- /dev/null +++ b/resources/views/admin/cities/create.blade.php @@ -0,0 +1,34 @@ +@extends('admin.layouts.app') + +@section('title', 'افزودن شهر') + +@section('content') +
+
افزودن شهر جدید
+
+ @csrf +
+ + + @error('name') +
{{ $message }}
@enderror +
+
+ + + @error('province_id') +
{{ $message }}
@enderror +
+ + انصراف +
+
+@endsection + diff --git a/resources/views/admin/cities/edit.blade.php b/resources/views/admin/cities/edit.blade.php new file mode 100644 index 0000000..29fd77c --- /dev/null +++ b/resources/views/admin/cities/edit.blade.php @@ -0,0 +1,31 @@ +@extends('admin.layouts.app') + +@section('content') +
+
ویرایش شهر: {{ $city->name }}
+
+
+ @csrf @method('PUT') +
+ + + @error('name') {{ $message }} @enderror +
+
+ + + @error('province_id') {{ $message }} @enderror +
+ +
+
+
+@endsection diff --git a/resources/views/admin/cities/index.blade.php b/resources/views/admin/cities/index.blade.php new file mode 100644 index 0000000..6ac570c --- /dev/null +++ b/resources/views/admin/cities/index.blade.php @@ -0,0 +1,69 @@ +@extends('admin.layouts.app') + +@section('title', 'مدیریت شهرها') + +@section('breadcrumb') +
+

مدیریت شهرها

+ +
+@endsection + +@section('content') +
+
+
+
لیست شهرها
+ افزودن شهر جدید +
+
+
+ +
+ +
+ + + + + + + + + + @foreach($cities as $city) + + + + + + @endforeach + +
نام شهراستانعملیات
{{ $city->name }}{{ $city->province->name ?? '-' }} + ویرایش +
+ @csrf @method('DELETE') + +
+
+
+
{{ $cities->links() }}
+
+
+
+@endsection diff --git a/resources/views/admin/provinces/create.blade.php b/resources/views/admin/provinces/create.blade.php new file mode 100644 index 0000000..cb2bf75 --- /dev/null +++ b/resources/views/admin/provinces/create.blade.php @@ -0,0 +1,20 @@ +@extends('admin.layouts.app') + +@section('content') +
+
افزودن استان جدید
+
+
+ @csrf +
+ + + @error('name') {{ $message }} @enderror +
+ +
+
+
+@endsection + diff --git a/resources/views/admin/provinces/edit.blade.php b/resources/views/admin/provinces/edit.blade.php new file mode 100644 index 0000000..0a53f15 --- /dev/null +++ b/resources/views/admin/provinces/edit.blade.php @@ -0,0 +1,19 @@ +@extends('admin.layouts.app') + +@section('content') +
+
ویرایش استان: {{ $province->name }}
+
+
+ @csrf @method('PUT') +
+ + + @error('name') {{ $message }} @enderror +
+ +
+
+
+@endsection diff --git a/resources/views/admin/provinces/index.blade.php b/resources/views/admin/provinces/index.blade.php new file mode 100644 index 0000000..b5adc64 --- /dev/null +++ b/resources/views/admin/provinces/index.blade.php @@ -0,0 +1,59 @@ +@extends('admin.layouts.app') + +@section('title', 'مدیریت استان‌ها') + +@section('breadcrumb') +
+

مدیریت استان‌ها

+ +
+@endsection + +@section('content') +
+
+
+
لیست استان‌ها
+ افزودن استان جدید +
+
+
+ + + + + + + + + + @foreach($provinces as $province) + + + + + + @endforeach + +
شناسهنام استانعملیات
{{ $province->id }}{{ $province->name }} + ویرایش +
+ @csrf @method('DELETE') + +
+
+
+
{{ $provinces->links() }}
+
+
+
+@endsection