From 67f9379e865a61ebd4d4707ed1a0357b5c36296a Mon Sep 17 00:00:00 2001 From: Windows Store Date: Thu, 20 Aug 2026 13:22:35 +0330 Subject: [PATCH] feat: add a list for flights in admin panel and add edit and delete for flights in admin panel --- .../Controllers/Admin/FlightController.php | 97 +++++++ .../Admins/FlightUpdatePostRequest.php | 66 +++++ app/Models/Flight.php | 3 +- composer.json | 1 + composer.lock | 134 ++++++++- resources/views/admin/flights/edit.blade.php | 269 ++++++++++++++++++ resources/views/admin/flights/index.blade.php | 161 +++++++++++ resources/views/flights/index.blade.php | 1 - 8 files changed, 729 insertions(+), 3 deletions(-) create mode 100644 app/Http/Controllers/Admin/FlightController.php create mode 100644 app/Http/Requests/Admins/FlightUpdatePostRequest.php create mode 100644 resources/views/admin/flights/edit.blade.php create mode 100644 resources/views/admin/flights/index.blade.php diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php new file mode 100644 index 0000000..a5c1576 --- /dev/null +++ b/app/Http/Controllers/Admin/FlightController.php @@ -0,0 +1,97 @@ +with([ + 'airline', + 'airport', + 'destinationAirport', + ]) + ->latest('id') + ->paginate(10); + foreach ($flights as $flight) { + $flight->start_date_fa = $flight->start_time + ? $flight->start_time->toJalali()->format('Y/m/d') + : null; + + $flight->end_date_fa = $flight->end_time + ? $flight->end_time->toJalali()->format('Y/m/d') + : null; + + $flight->start_time_fa = $flight->start_time + ? $flight->start_time->format('H:i') + : null; + + $flight->end_time_fa = $flight->end_time + ? $flight->end_time->format('H:i') + : null; + } + return view('admin.flights.index', compact('flights')); + } + public function edit(Flight $flight) + { + $airlines = Airline::query() + ->orderBy('name') + ->get(); + + $airports = Airport::query() + ->orderBy('name') + ->get(); + + return view('admin.flights.edit', compact('flight', 'airlines', 'airports')); + } + + /** + * Update the specified flight. + */ + public function update(FlightUpdatePostRequest $request, Flight $flight) + { + $data = $request->validated(); + + $start = verta::parse($data['start_time'])->datetime(); + $end = verta::parse($data['end_time'])->datetime(); + + $data['start_time'] = $start; + $data['end_time'] = $end; + + $flight->update($data); + + return redirect()->route('admin.flights.index'); + } + + + public function create() + { + $airports = Airport::all(); + + return view('admin.flights.create', compact('airports')); + } + + public function destroy(Flight $flight) + { + $flight->delete(); + + return redirect() + ->route('admin.flights.index') + ->with('success', 'پرواز با موفقیت حذف شد.'); + } + + public function store() + { + + } + +} diff --git a/app/Http/Requests/Admins/FlightUpdatePostRequest.php b/app/Http/Requests/Admins/FlightUpdatePostRequest.php new file mode 100644 index 0000000..19fb80a --- /dev/null +++ b/app/Http/Requests/Admins/FlightUpdatePostRequest.php @@ -0,0 +1,66 @@ + [ + 'required', + 'int', + 'digits:10', + ], + + 'airline_id' => [ + 'required', + 'integer', + 'exists:airlines,id', + ], + + 'origin_airports_id' => [ + 'required', + 'integer', + 'exists:airports,id', + ], + + 'destination_airports_id' => [ + 'required', + 'integer', + 'exists:airports,id', + 'different:origin_airports_id', + ], + + 'start_time' => [ + 'required', + 'string', + ], + + 'end_time' => [ + 'required', + 'string', + ], + + 'price' => [ + 'required', + 'integer', + 'min:0', + ], + + 'capacity' => [ + 'required', + 'integer', + 'min:1', + ], + ]; + } +} diff --git a/app/Models/Flight.php b/app/Models/Flight.php index 5ea9ac7..25f39da 100644 --- a/app/Models/Flight.php +++ b/app/Models/Flight.php @@ -8,7 +8,7 @@ namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; - +use Illuminate\Database\Eloquent\SoftDeletes; /** * Class Flight * @@ -59,6 +59,7 @@ class Flight extends Model /** * @var mixed|string */ + use SoftDeletes; public mixed $end_date_fa; protected $table = 'flights'; diff --git a/composer.json b/composer.json index da35d55..d8ec479 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ "hekmatinasser/verta": "^9.0", "laravel/framework": "^12.0", "laravel/tinker": "^2.10.1", + "morilog/jalali": "^3.5", "sadegh19b/laravel-persian-validation": "^2.1" }, "require-dev": { diff --git a/composer.lock b/composer.lock index c068e1c..80e8679 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,75 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d2f9c73ad216c4d120251d41cec0c1ee", + "content-hash": "680dc3ad2c8f1547466b6104dd7f0c6f", "packages": [ + { + "name": "beberlei/assert", + "version": "v3.3.4", + "source": { + "type": "git", + "url": "https://github.com/beberlei/assert.git", + "reference": "f193f4613c7d7fbcee2c05e4daff4061d49c040e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/beberlei/assert/zipball/f193f4613c7d7fbcee2c05e4daff4061d49c040e", + "reference": "f193f4613c7d7fbcee2c05e4daff4061d49c040e", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-json": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "*", + "phpstan/phpstan": "*", + "phpunit/phpunit": ">=6.0.0", + "yoast/phpunit-polyfills": "^0.1.0" + }, + "suggest": { + "ext-intl": "Needed to allow Assertion::count(), Assertion::isCountable(), Assertion::minCount(), and Assertion::maxCount() to operate on ResourceBundles" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Assert/functions.php" + ], + "psr-4": { + "Assert\\": "lib/Assert" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de", + "role": "Lead Developer" + }, + { + "name": "Richard Quadling", + "email": "rquadling@gmail.com", + "role": "Collaborator" + } + ], + "description": "Thin assertion library for input validation in business models.", + "keywords": [ + "assert", + "assertion", + "validation" + ], + "support": { + "issues": "https://github.com/beberlei/assert/issues", + "source": "https://github.com/beberlei/assert/tree/v3.3.4" + }, + "time": "2026-06-10T19:47:05+00:00" + }, { "name": "brick/math", "version": "0.14.8", @@ -2311,6 +2378,71 @@ ], "time": "2026-01-02T08:56:05+00:00" }, + { + "name": "morilog/jalali", + "version": "v3.5.0", + "source": { + "type": "git", + "url": "https://github.com/morilog/jalali.git", + "reference": "40b906c405b72edd20e73797b40be1e650e872c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/morilog/jalali/zipball/40b906c405b72edd20e73797b40be1e650e872c1", + "reference": "40b906c405b72edd20e73797b40be1e650e872c1", + "shasum": "" + }, + "require": { + "beberlei/assert": "^3.0", + "nesbot/carbon": "^1.21 || ^2.0 || ^3.0", + "php": "^7.1 | ^8.0" + }, + "require-dev": { + "phpunit/phpunit": ">4.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Morilog\\Jalali\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Milad Rey", + "email": "miladr@gmail.com" + }, + { + "name": "Morteza Parvini", + "email": "m.parvini@outlook.com" + } + ], + "description": "This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.", + "keywords": [ + "Jalali", + "date", + "datetime", + "laravel", + "morilog" + ], + "support": { + "issues": "https://github.com/morilog/jalali/issues", + "source": "https://github.com/morilog/jalali/tree/v3.5.0" + }, + "funding": [ + { + "url": "https://issuehunt.io/r/morilog", + "type": "issuehunt" + } + ], + "time": "2025-12-25T07:12:28+00:00" + }, { "name": "nesbot/carbon", "version": "3.13.2", diff --git a/resources/views/admin/flights/edit.blade.php b/resources/views/admin/flights/edit.blade.php new file mode 100644 index 0000000..59caa1b --- /dev/null +++ b/resources/views/admin/flights/edit.blade.php @@ -0,0 +1,269 @@ +@extends('dashboard.layouts.app') + +@section('title', 'ویرایش پرواز') + +@section('account-content') + +
+ + @if(session('success')) +
+
+ {{ session('success') }} +
+
+ @endif + +
+ +
+ +
+ +@endsection + +@section('scripts') + + + +@endsection diff --git a/resources/views/admin/flights/index.blade.php b/resources/views/admin/flights/index.blade.php new file mode 100644 index 0000000..da4ca98 --- /dev/null +++ b/resources/views/admin/flights/index.blade.php @@ -0,0 +1,161 @@ +@extends('dashboard.layouts.app') + +@section('title', 'لیست پروازها') + +@section('account-content') + +
+ + @if(session('success')) +
+
+ {{ session('success') }} +
+
+ @endif + +
+ +
+ +
+ +@endsection diff --git a/resources/views/flights/index.blade.php b/resources/views/flights/index.blade.php index bec059b..ae348c9 100644 --- a/resources/views/flights/index.blade.php +++ b/resources/views/flights/index.blade.php @@ -77,7 +77,6 @@
{{ number_format($flight->price) }} تومان
- اکنون ثبت کن