Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| StoreQuestionRequest | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
| authorize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| prepareForValidation | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| rules | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| attributes | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\Bo\Questions; |
| 4 | |
| 5 | use App\Enums\QuestionType; |
| 6 | use Illuminate\Foundation\Http\FormRequest; |
| 7 | use Illuminate\Validation\Rules\Enum; |
| 8 | |
| 9 | class StoreQuestionRequest extends FormRequest |
| 10 | { |
| 11 | /** |
| 12 | * Determine if the user is authorized to make this request. |
| 13 | * |
| 14 | * @return boolean |
| 15 | */ |
| 16 | public function authorize(): bool |
| 17 | { |
| 18 | return auth('backend')->check(); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Prepare the data for validation. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | protected function prepareForValidation(): void |
| 27 | { |
| 28 | $this->merge([ |
| 29 | 'brand_id' => collect($this->brand)->pluck('id')->first() |
| 30 | ]); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the validation rules that apply to the request. |
| 35 | * |
| 36 | * @return array |
| 37 | */ |
| 38 | public function rules(): array |
| 39 | { |
| 40 | return [ |
| 41 | 'question' => 'required|string|min:10|max:255', |
| 42 | 'type' => ['required', new Enum(QuestionType::class)], |
| 43 | 'brand_id' => 'required|integer|min:0|exists:brands,id', |
| 44 | ]; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get custom attributes for validator errors. |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | public function attributes(): array |
| 53 | { |
| 54 | return [ |
| 55 | 'question' => trans('Texte de la question'), |
| 56 | 'type' => trans('Type de question'), |
| 57 | 'brand_id' => trans('Id de la marque'), |
| 58 | ]; |
| 59 | } |
| 60 | } |