79 lines
2.1 KiB
PHP
79 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Modules\RestaurantDelivery\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Modules\RestaurantDelivery\Enums\DeliveryStatus;
|
|
|
|
class UpdateDeliveryStatusRequest 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 the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'status' => [
|
|
'required',
|
|
'string',
|
|
Rule::in(array_column(DeliveryStatus::cases(), 'value')),
|
|
],
|
|
'changed_by' => [
|
|
'nullable',
|
|
'string',
|
|
Rule::in(['customer', 'restaurant', 'rider', 'admin', 'system', 'api']),
|
|
],
|
|
'notes' => ['nullable', 'string', 'max:500'],
|
|
'latitude' => ['nullable', 'numeric', 'between:-90,90'],
|
|
'longitude' => ['nullable', 'numeric', 'between:-180,180'],
|
|
|
|
// For delivery proof
|
|
'photo' => ['nullable', 'string'],
|
|
'signature' => ['nullable', 'string'],
|
|
'recipient_name' => ['nullable', 'string', 'max:100'],
|
|
|
|
// For cancellation
|
|
'cancellation_reason' => [
|
|
'nullable',
|
|
'required_if:status,cancelled',
|
|
'string',
|
|
'max:255',
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'status' => 'delivery status',
|
|
'changed_by' => 'status changed by',
|
|
'cancellation_reason' => 'cancellation reason',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get the error messages for the defined validation rules.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'status.in' => 'The selected status is invalid.',
|
|
'cancellation_reason.required_if' => 'A cancellation reason is required when cancelling a delivery.',
|
|
];
|
|
}
|
|
}
|