2023-06-15 12:28:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
2023-10-06 15:00:42 +02:00
|
|
|
namespace App\Http\Requests\Bo\Questions;
|
2023-06-15 12:28:05 +02:00
|
|
|
|
2023-06-26 10:13:19 +02:00
|
|
|
use App\Enums\QuestionType;
|
2023-06-15 12:28:05 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2023-09-04 13:08:34 +02:00
|
|
|
use Illuminate\Validation\Rules\Enum;
|
2023-06-15 12:28:05 +02:00
|
|
|
|
|
|
|
|
class StoreQuestionRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the user is authorized to make this request.
|
|
|
|
|
*
|
|
|
|
|
* @return boolean
|
|
|
|
|
*/
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
2023-10-06 15:00:42 +02:00
|
|
|
return auth('backend')->check();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the data for validation.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
|
|
|
|
$this->merge([
|
|
|
|
|
'brand_id' => collect($this->brand)->pluck('id')->first()
|
|
|
|
|
]);
|
2023-06-15 12:28:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2023-06-26 10:13:19 +02:00
|
|
|
'question' => 'required|string|min:10|max:255',
|
2023-09-04 13:08:34 +02:00
|
|
|
'type' => ['required', new Enum(QuestionType::class)],
|
2023-06-26 10:13:19 +02:00
|
|
|
'brand_id' => 'required|integer|min:0|exists:brands,id',
|
2023-06-15 12:28:05 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get custom attributes for validator errors.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2023-06-15 13:15:26 +02:00
|
|
|
'question' => trans('Texte de la question'),
|
2023-09-04 13:08:34 +02:00
|
|
|
'type' => trans('Type de question'),
|
2023-06-15 13:15:26 +02:00
|
|
|
'brand_id' => trans('Id de la marque'),
|
2023-06-15 12:28:05 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|