diff --git a/app/Http/Requests/StoreParkingLotRequest.php b/app/Http/Requests/StoreParkingLotRequest.php index 40b07f4..9f8cc8f 100644 --- a/app/Http/Requests/StoreParkingLotRequest.php +++ b/app/Http/Requests/StoreParkingLotRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rule; class StoreParkingLotRequest extends FormRequest { @@ -22,7 +23,10 @@ class StoreParkingLotRequest extends FormRequest public function rules(): array { return [ - 'name' => 'required|string|max:255', + 'name' => [ + 'required', 'string', 'max:255', + Rule::unique('parking_lots', 'name')->ignore($this->route('parkingLot')), + ], 'address' => 'required|string|max:500', 'total_capacity' => 'required|integer|min:1|max:10000', 'price_per_hour' => 'required|numeric|min:0.01|max:1000', @@ -38,6 +42,7 @@ class StoreParkingLotRequest extends FormRequest { return [ 'name.required' => 'اسم الموقف مطلوب.', + 'name.unique' => 'يوجد موقف بهذا الاسم مسبقاً.', 'address.required' => 'العنوان مطلوب.', 'total_capacity.required' => 'السعة مطلوبة.', 'price_per_hour.required' => 'سعر الساعة مطلوب.', diff --git a/database/migrations/2026_04_15_131513_add_unique_name_to_parking_lots_table.php b/database/migrations/2026_04_15_131513_add_unique_name_to_parking_lots_table.php new file mode 100644 index 0000000..8c5af6d --- /dev/null +++ b/database/migrations/2026_04_15_131513_add_unique_name_to_parking_lots_table.php @@ -0,0 +1,28 @@ +unique('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('parking_lots', function (Blueprint $table) { + $table->dropUnique(['name']); + }); + } +};