check() and Gate::check('orderThings', Order::class); } /** * Prepare the data for validation. * * @return void */ protected function prepareForValidation() { $mode = null; try { $mode = PaymentModeEnum::make(\intval($this->mode)); } catch (\TypeError | \BadMethodCallException $e) { $mode = null; } $this->merge([ 'modeEnum' => $mode ]); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'mode' => [ 'required', new EnumIsValidRule(PaymentModeEnum::class), // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!$this->modeEnum or !Gate::check('isAvailable', [PaymentMode::class, $this->modeEnum])) { $fail(\trans('Ce mode de paiement n\'est pas disponible.')); } } ] ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'mode' => trans('moyen de paiement') ]; } }