100 lines
4 KiB
PHP
100 lines
4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Requests\Back\Recipes;
|
|
|
|
use App\Services\AdminAuthService;
|
|
use Domain\Models\ValueObjects\Products\ProductCategory;
|
|
use Domain\Models\ValueObjects\Recipes\ConsumptionTime;
|
|
use Domain\Models\ValueObjects\Recipes\Inspiration;
|
|
use Domain\Models\ValueObjects\Recipes\Season;
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Validation\Rule;
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
class StoreRecipeRequest extends FormRequest
|
|
{
|
|
protected const int MAX_FILE_SIZE_KB = 5120;
|
|
|
|
protected const int PICTURE_WIDTH = 800;
|
|
|
|
protected const int PICTURE_HEIGHT = 800;
|
|
|
|
public function __construct(
|
|
private readonly AdminAuthService $authService
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return $this->authService->check();
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, \Illuminate\Validation\Rule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'seo_title' => ['required', 'string', 'between:45,70'],
|
|
'seo_description' => ['required', 'string', 'between:50,160'],
|
|
'product_category' => ['required', new Enum(ProductCategory::class)],
|
|
'consomption_time' => ['required', new Enum(ConsumptionTime::class)],
|
|
'inspiration' => ['required', new Enum(Inspiration::class)],
|
|
'season' => ['required', new Enum(Season::class)],
|
|
'description' => ['nullable', 'string'],
|
|
'details' => ['nullable', 'string'],
|
|
'ingredients_list' => ['required', 'string'],
|
|
'preparation_steps' => ['required', 'string'],
|
|
'tips_and_advices' => ['nullable', 'string'],
|
|
'picture' => [
|
|
'required',
|
|
Rule::imageFile()
|
|
->max(self::MAX_FILE_SIZE_KB)
|
|
->dimensions(
|
|
Rule::dimensions()
|
|
->width(static::PICTURE_WIDTH)
|
|
->height(static::PICTURE_HEIGHT)
|
|
),
|
|
],
|
|
'picture_alt' => ['required', 'string', 'min:4', 'max:75'],
|
|
'picture_title' => ['required', 'string', 'min:4', 'max:75'],
|
|
'products' => ['nullable', 'array'],
|
|
'products.*' => ['string', 'uuid', 'exists:products,id'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Get custom attributes for validator errors.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
public function attributes(): array
|
|
{
|
|
return [
|
|
'name' => trans('validation.attributes.name'),
|
|
'seo_title' => trans('validation.attributes.seo_title'),
|
|
'seo_description' => trans('validation.attributes.seo_description'),
|
|
'product_category' => trans('validation.attributes.product_category'),
|
|
'consomption_time' => trans('validation.attributes.consomption_time'),
|
|
'inspiration' => trans('validation.attributes.inspiration'),
|
|
'season' => trans('validation.attributes.season'),
|
|
'description' => trans('validation.attributes.description'),
|
|
'details' => trans('validation.attributes.details'),
|
|
'ingredients_list' => trans('validation.attributes.ingredients_list'),
|
|
'preparation_steps' => trans('validation.attributes.preparation_steps'),
|
|
'tips_and_advices' => trans('validation.attributes.tips_and_advices'),
|
|
'picture' => trans('validation.attributes.picture'),
|
|
'picture_alt' => trans('validation.attributes.picture_alt'),
|
|
'picture_title' => trans('validation.attributes.picture_title'),
|
|
'products' => trans('validation.attributes.associated_products'),
|
|
];
|
|
}
|
|
}
|