initial: project state before operator dashboard card redesign
This commit is contained in:
commit
e0aed8eed7
113 files changed
+20074
No files matched your search
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Models\ParkingLot;
|
||||
|
||||
class StoreBookingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to this request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'parking_lot_id' => 'required|exists:parking_lots,id',
|
||||
'customer_name' => 'required|string|max:255',
|
||||
'phone' => 'required|string|max:20|regex:/^09[0-9]{8}$/',
|
||||
'start_time' => 'required|date|after:now',
|
||||
'end_time' => 'required|date|after:start_time',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom messages for validator errors.
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'phone.regex' => 'رقم الهاتف يجب أن يكون رقم سوري صالح (09xxxxxxxx).',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the validator after the validation rules have run.
|
||||
*/
|
||||
protected function passedValidation(): void
|
||||
{
|
||||
$lot = ParkingLot::findOrFail($this->parking_lot_id);
|
||||
$activeCount = $lot->carRegistries()->active()->count();
|
||||
|
||||
if ($lot->total_capacity <= $activeCount) {
|
||||
throw \Illuminate\Validation\ValidationException::withMessages([
|
||||
'parking_lot_id' => ['الموقف ممتلئ حالياً. يرجى اختيار موقف آخر أو المحاولة لاحقاً.'],
|
||||
])->status(409);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in new issue
Block a user