feat: ingredientds
This commit is contained in:
@@ -10,6 +10,6 @@ enum MealPostType: string
|
||||
case BRUNCH = 'brunch';
|
||||
case SNACK = 'snack';
|
||||
case DRINK = 'drink';
|
||||
case SUPPLEMENT = "supplement";
|
||||
case OTHER = "other";
|
||||
case SUPPLEMENT = 'supplement';
|
||||
case OTHER = 'other';
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class MealPostIngredientsRequest extends FormRequest
|
||||
'meal_posts_id' => ['required', 'exists:meal_posts,id'],
|
||||
'position' => ['required', 'integer'],
|
||||
'ingredient' => ['required', 'string'],
|
||||
'quantity' => ['required', 'integer', 'min:1'],
|
||||
'unit' => ['required', Rule::enum(IngredientUnit::class)],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@ class MealPostsRequest extends FormRequest
|
||||
'type' => [$isCreating ? 'required' : 'sometimes', Rule::enum(MealPostType::class)],
|
||||
'visibility' => ['sometimes', Rule::enum(MealPostVisibility::class)],
|
||||
'ingredients' => ['sometimes', 'array'],
|
||||
'ingredients.*' => ['required', 'array:position,ingredient,unit'],
|
||||
'ingredients.*' => ['required', 'array:position,ingredient,quantity,unit'],
|
||||
'ingredients.*.position' => ['required', 'integer', 'min:0'],
|
||||
'ingredients.*.ingredient' => ['required', 'string', 'max:255'],
|
||||
'ingredients.*.quantity' => ['required', 'integer', 'min:1'],
|
||||
'ingredients.*.unit' => ['required', Rule::enum(IngredientUnit::class)],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ class MealPostIngredientsResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'position' => $this->position,
|
||||
'ingredient' => $this->ingredient,
|
||||
'quantity' => $this->quantity,
|
||||
'unit' => $this->unit,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
|
||||
@@ -12,6 +12,7 @@ class MealPostIngredients extends Model
|
||||
'meal_posts_id',
|
||||
'position',
|
||||
'ingredient',
|
||||
'quantity',
|
||||
'unit',
|
||||
];
|
||||
|
||||
@@ -23,6 +24,7 @@ class MealPostIngredients extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'quantity' => 'integer',
|
||||
'unit' => IngredientUnit::class,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user