2023-03-23 09:08:28 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Recipes;
|
|
|
|
|
|
2023-04-19 08:14:36 +00:00
|
|
|
use App\Enums\Recipes\CookingEnum;
|
|
|
|
|
use App\Enums\Recipes\DifficultyEnum;
|
2023-04-19 07:49:24 +00:00
|
|
|
use CodeZero\UniqueTranslation\UniqueTranslationRule;
|
|
|
|
|
use Illuminate\Validation\Rules\Enum;
|
|
|
|
|
|
2023-03-23 09:08:28 +01:00
|
|
|
class UpdateRecipeRequest extends StoreRecipeRequest
|
|
|
|
|
{
|
2023-04-19 07:49:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get the validation rules that apply to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function rules()
|
|
|
|
|
{
|
|
|
|
|
$rules = [
|
|
|
|
|
'seo_title' => 'required|min:3|max:70',
|
|
|
|
|
'seo_description' => 'required|min:50|max:160',
|
|
|
|
|
'name' => 'required|min:3|max:255',
|
|
|
|
|
'slug' => UniqueTranslationRule::for('recipes')->ignore($this->recipe->id),
|
|
|
|
|
'picture_alt' => 'required|min:3|max:255',
|
|
|
|
|
'picture_title' => 'required|min:3|max:255',
|
|
|
|
|
'picture_thumbnail_alt' => 'required|min:3|max:255',
|
|
|
|
|
'picture_thumbnail_title' => 'required|min:3|max:255',
|
|
|
|
|
'ingredients' => [
|
|
|
|
|
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
|
|
|
|
'present', 'array', function ($attribute, array $value, $fail) {
|
|
|
|
|
if (1 > count($value)) {
|
|
|
|
|
$fail(\trans('You must fill in at least 1 line of ingredients.'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
'ingredients.*' => 'nullable|array',
|
|
|
|
|
'ingredients.*.header' => 'nullable|string|min:3|max:255',
|
|
|
|
|
'ingredients.*.value' => 'nullable|string|min:3|max:255',
|
|
|
|
|
'teaser' => 'required|min:50|max:160',
|
|
|
|
|
'steps' => 'required|string|min:15',
|
|
|
|
|
'difficulty' => [new Enum(DifficultyEnum::class)],
|
|
|
|
|
'preparation' => 'required|numeric|min:1|max:1440',
|
|
|
|
|
'duration' => 'required|numeric|min:1|max:1440',
|
|
|
|
|
'tips' => 'required|string|min:15',
|
|
|
|
|
'cooking' => [new Enum(CookingEnum::class)],
|
|
|
|
|
'range_id' => 'required|exists:ranges,id',
|
|
|
|
|
'status' => 'required|boolean'
|
|
|
|
|
];
|
|
|
|
|
return \array_merge(
|
|
|
|
|
$rules,
|
2023-05-04 12:07:27 +02:00
|
|
|
$this->pictureRules('picture', 1600, 900, 1600, 900, true),
|
|
|
|
|
$this->pictureRules('picture_thumbnail', 430, 242, 430, 242, true),
|
2023-04-19 07:49:24 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-03-23 09:08:28 +01:00
|
|
|
}
|