58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests\Bo\Orders;
|
|
|
|
use App\Enums\Order\DeliveryStatus;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Kwaadpepper\Enum\Rules\EnumIsValidRule;
|
|
|
|
class ChangeOrderDeliveryStatusRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return auth('backend')->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'delivery_status' => [
|
|
'required', new EnumIsValidRule(DeliveryStatus::class),
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
function ($attribute, $value, $fail) {
|
|
$deliveryStatus = DeliveryStatus::make(\intval($this->delivery_status));
|
|
if ($this->order->delivery_status->value > $deliveryStatus->value) {
|
|
$fail(trans(':attribute Il n\'est pas possible de revenir en arrière sur le statut'));
|
|
return;
|
|
}
|
|
if ($deliveryStatus->value - $this->order->delivery_status->value !== 1) {
|
|
$fail(trans(':attribute Il n\'est possible de modifier le statut que sur le statut suivant'));
|
|
return;
|
|
}
|
|
}
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function attributes()
|
|
{
|
|
return [
|
|
'delivery_status' => trans('Statut de livraison')
|
|
];
|
|
}
|
|
}
|