Update recipe fields
This commit is contained in:
parent
4356a0e4c9
commit
f128865453
13 changed files with 21 additions and 146 deletions
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Enums\Recipes;
|
||||
|
||||
use App\Traits\Enums\BaseEnum;
|
||||
|
||||
enum CookingEnum : int
|
||||
{
|
||||
use BaseEnum;
|
||||
|
||||
case cook = 1;
|
||||
case grill = 2;
|
||||
|
||||
/**
|
||||
* Custom added images definition
|
||||
*/
|
||||
private const IMAGES = [
|
||||
self::cook->name => 'cook.png',
|
||||
self::grill->name => 'grill.png',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get image
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function image(): string
|
||||
{
|
||||
return self::IMAGES[$this->name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enum images
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
public static function toImages(): array
|
||||
{
|
||||
return self::IMAGES;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\Recipes;
|
||||
|
||||
use App\Enums\Recipes\CookingEnum;
|
||||
use App\Enums\Recipes\DifficultyEnum;
|
||||
use App\Traits\Requests\HasPicture;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
|
@ -68,10 +67,8 @@ class StoreRecipeRequest extends FormRequest
|
|||
'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',
|
||||
'duration' => 'required|string|min:1|max:150',
|
||||
'tips' => 'required|string|min:15',
|
||||
'cooking' => [new Enum(CookingEnum::class)],
|
||||
'range_id' => 'required|exists:ranges,id',
|
||||
'status' => 'required|boolean'
|
||||
];
|
||||
|
|
@ -101,10 +98,8 @@ class StoreRecipeRequest extends FormRequest
|
|||
'teaser' => trans('teaser'),
|
||||
'steps' => trans('steps'),
|
||||
'difficulty' => trans('difficulty'),
|
||||
'preparation' => trans('preparation'),
|
||||
'duration' => trans('duration'),
|
||||
'tips' => trans('tips'),
|
||||
'cooking' => trans('cooking'),
|
||||
'range_id' => trans('range'),
|
||||
'status' => trans('publish')
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
namespace App\Http\Requests\Bo\Recipes;
|
||||
|
||||
use App\Enums\Recipes\CookingEnum;
|
||||
use App\Enums\Recipes\DifficultyEnum;
|
||||
use CodeZero\UniqueTranslation\UniqueTranslationRule;
|
||||
use Illuminate\Validation\Rules\Enum;
|
||||
|
||||
class UpdateRecipeRequest extends StoreRecipeRequest
|
||||
{
|
||||
|
|
@ -17,36 +14,10 @@ class UpdateRecipeRequest extends StoreRecipeRequest
|
|||
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'
|
||||
'slug' => UniqueTranslationRule::for('recipes')->ignore($this->recipe->id)
|
||||
];
|
||||
return \array_merge(
|
||||
parent::rules(),
|
||||
$rules,
|
||||
$this->pictureRules('picture', 1600, 900, 1600, 900, true),
|
||||
$this->pictureRules('picture_thumbnail', 430, 242, 430, 242, true),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\Recipes\CookingEnum;
|
||||
use App\Enums\Recipes\DifficultyEnum;
|
||||
use App\Lib\Helpers\FileStorageHelper;
|
||||
use App\Lib\Helpers\ToolboxHelper;
|
||||
|
|
@ -12,7 +11,6 @@ use Illuminate\Support\Str;
|
|||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* @property integer $id
|
||||
* @property integer $range_id
|
||||
* @property string $seo_title
|
||||
* @property string $seo_description
|
||||
|
|
@ -23,17 +21,15 @@ use Spatie\Translatable\HasTranslations;
|
|||
* @property string $ingredients
|
||||
* @property string $teaser
|
||||
* @property string $steps
|
||||
* @property boolean $difficulty
|
||||
* @property boolean $preparation
|
||||
* @property boolean $duration
|
||||
* @property \App\Enums\Recipes\DifficultyEnum $difficulty
|
||||
* @property string $duration
|
||||
* @property string $tips
|
||||
* @property boolean $cooking
|
||||
* @property boolean $status
|
||||
* @property integer $order
|
||||
* @property string $created_at
|
||||
* @property string $updated_at
|
||||
* @property Product[] $products
|
||||
* @property Range $range
|
||||
* @property \App\Models\Product[] $products
|
||||
* @property \App\Models\Range $range
|
||||
*/
|
||||
class Recipe extends Model
|
||||
{
|
||||
|
|
@ -59,10 +55,8 @@ class Recipe extends Model
|
|||
'teaser',
|
||||
'steps',
|
||||
'difficulty',
|
||||
'preparation',
|
||||
'duration',
|
||||
'tips',
|
||||
'cooking',
|
||||
'status',
|
||||
'order',
|
||||
'created_at',
|
||||
|
|
@ -76,8 +70,7 @@ class Recipe extends Model
|
|||
*/
|
||||
protected $casts = [
|
||||
'ingredients' => 'json',
|
||||
'difficulty' => DifficultyEnum::class,
|
||||
'cooking' => CookingEnum::class,
|
||||
'difficulty' => DifficultyEnum::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -95,6 +88,7 @@ class Recipe extends Model
|
|||
'picture_thumbnail_alt',
|
||||
'picture_thumbnail_title',
|
||||
'ingredients',
|
||||
'duration',
|
||||
'teaser',
|
||||
'steps',
|
||||
'tips',
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final class ConceptFactory extends Factory
|
|||
|
||||
return [
|
||||
'seo_title' => fake()->word,
|
||||
'seo_description' => fake()->text,
|
||||
'seo_description' => fake()->text(160),
|
||||
'name' => $name,
|
||||
'slug' => Str::slug($name),
|
||||
'title' => fake()->word,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ final class HomeFactory extends Factory
|
|||
|
||||
return [
|
||||
'seo_title' => fake()->word,
|
||||
'seo_description' => fake()->text,
|
||||
'seo_description' => fake()->text(160),
|
||||
'part1_title' => fake()->word,
|
||||
'part1_subtitle' => fake()->word,
|
||||
'part1_text_1' => fake()->text,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ final class ProductFactory extends Factory
|
|||
|
||||
return [
|
||||
'seo_title' => fake()->word,
|
||||
'seo_description' => fake()->text,
|
||||
'seo_description' => fake()->text(160),
|
||||
'label' => $label,
|
||||
'slug' => Str::slug($label),
|
||||
'description' => fake()->word,
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ final class RangeFactory extends Factory
|
|||
$label = fake()->unique()->word;
|
||||
return [
|
||||
'seo_title' => fake()->word,
|
||||
'seo_description' => fake()->text,
|
||||
'seo_description' => fake()->text(160),
|
||||
'label' => $label,
|
||||
'slug' => Str::slug($label),
|
||||
'picto' => \collect(PictoEnum::cases())->random(),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\Recipes\DifficultyEnum;
|
||||
use App\Enums\Recipes\CookingEnum;
|
||||
use App\Models\Range;
|
||||
use App\Models\Recipe;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
|
@ -39,7 +38,7 @@ final class RecipeFactory extends Factory
|
|||
|
||||
return [
|
||||
'seo_title' => fake()->word,
|
||||
'seo_description' => fake()->text,
|
||||
'seo_description' => fake()->text(160),
|
||||
'name' => $name,
|
||||
'slug' => Str::slug($name),
|
||||
'picture_alt' => fake()->word,
|
||||
|
|
@ -47,13 +46,11 @@ final class RecipeFactory extends Factory
|
|||
'picture_thumbnail_alt' => fake()->word,
|
||||
'picture_thumbnail_title' => fake()->word,
|
||||
'ingredients' => $ingredients,
|
||||
'teaser' => fake()->text,
|
||||
'teaser' => fake()->text(160),
|
||||
'steps' => fake()->text,
|
||||
'difficulty' => \collect(DifficultyEnum::cases())->random(),
|
||||
'preparation' => fake()->numberBetween(0, 60),
|
||||
'duration' => fake()->numberBetween(0, 60),
|
||||
'tips' => fake()->text,
|
||||
'cooking' => \collect(CookingEnum::cases())->random(),
|
||||
'range_id' => fake()->randomElement(Range::pluck('id')),
|
||||
'status' => fake()->boolean(75),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -28,13 +28,9 @@ return new class extends Migration
|
|||
$table->json('ingredients')->comment('Liste d\'ingrédients de la recette');
|
||||
$table->json('teaser')->comment('Phrase d\'accroche');
|
||||
$table->json('steps')->comment('Étapes à suivre pour réaliser la recette');
|
||||
$table->smallInteger('preparation')->unsigned()
|
||||
->comment('Préparation nécessaire à la réalisation de la recette');
|
||||
$table->smallInteger('duration')->unsigned()
|
||||
->comment('Temps de réalisation de la recette');
|
||||
$table->json('duration')->comment('Temps de réalisation de la recette');
|
||||
$table->tinyInteger('difficulty')->comment('Niveau de difficulté de la recette');
|
||||
$table->json('tips')->comment('Astuces concernant cette recette');
|
||||
$table->tinyInteger('cooking')->comment('Cuisson de la recette');
|
||||
$table->unsignedBigInteger('range_id')->comment('Espèce d\'animal utilisé');
|
||||
$table->boolean('status')->comment('État de la recette');
|
||||
$table->integer('order')->unsigned()->comment('Classement de la recette');
|
||||
|
|
|
|||
|
|
@ -250,7 +250,6 @@
|
|||
"Filter by range": "Nach Bereich filtern",
|
||||
"Reset filter": "Filter zurücksetzen",
|
||||
"Unfortunately no market in your area.": "Leider kein Markt in Ihrer Nähe.",
|
||||
"Must be in minutes." : "Muss in Minuten sein.",
|
||||
"Must have 8 decimal maximum. Can be found in Google Maps." : "Muss maximal 8 Dezimalstellen haben. Zu finden in Google Maps.",
|
||||
"You already created 8 :models. Please delete or edit an existing one.": "Sie haben bereits 8 :models erstellt. Bitte löschen oder bearbeiten Sie einen vorhandenen."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ return [
|
|||
'messages' => [
|
||||
'has_been_created' => ':model has been created',
|
||||
'cannot_be_created' => ':model cannot be created',
|
||||
'has_been_updated' => ':model has be created',
|
||||
'has_been_updated' => ':model has been updated',
|
||||
'cannot_be_updated' => ':model cannot be updated',
|
||||
'has_been_deleted' => ':model has been deleted',
|
||||
'cannot_be_deleted' => ':model cannot be deleted'
|
||||
|
|
|
|||
|
|
@ -290,58 +290,22 @@
|
|||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- COOKING --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="border bg-white p-3">
|
||||
<legend>{{ __('Cooking') }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
@include('bo.partials.inputs.tinyint-enum', [
|
||||
'id' => 'recipesCooking',
|
||||
'label' => __('Cooking associated'),
|
||||
'name' => 'cooking',
|
||||
'model' => $recipeModel ?? null,
|
||||
'required' => true,
|
||||
'associatedModels' => \App\Enums\Recipes\CookingEnum::toArray(),
|
||||
'helper' => __('Chose one cooking among this list.'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- PREPARATION --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="border bg-white p-3">
|
||||
<legend>{{ __('Preparation') }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
@include('bo.partials.inputs.int-number', [
|
||||
'id' => 'recipePreparation',
|
||||
'label' => __('Preparation needed to make the :model', ['model' => Str::singular(__('models.classes.recipes'))]),
|
||||
'name' => 'preparation',
|
||||
'model' => $recipeModel ?? null,
|
||||
'min' => 0,
|
||||
'required' => true,
|
||||
'helper' => __('Must be in minutes.'),
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
{{-- DURATION --}}
|
||||
<div class="col-12 col-md-6 mb-3">
|
||||
<fieldset class="border bg-white p-3">
|
||||
<legend>{{ __('Duration') }}</legend>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-3">
|
||||
@include('bo.partials.inputs.int-number', [
|
||||
@include('bo.partials.inputs.varchar', [
|
||||
'id' => 'recipeDuration',
|
||||
'hasWordCounter' => true,
|
||||
'label' => __('Time to complete the :model', ['model' => Str::singular(__('models.classes.recipes'))]),
|
||||
'name' => 'duration',
|
||||
'model' => $recipeModel ?? null,
|
||||
'min' => 0,
|
||||
'max' => 150,
|
||||
'required' => true,
|
||||
'helper' => __('Must be in minutes.'),
|
||||
'helper' => '',
|
||||
])
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue