feat: meal post visibility

This commit is contained in:
2026-05-16 17:32:02 +02:00
parent 7b8ede2a1a
commit 1964b60949
9 changed files with 145 additions and 7 deletions
+8 -3
View File
@@ -2,22 +2,26 @@
namespace App\Http\Requests;
use App\Enums\MealPostVisibility;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class MealPostsRequest extends FormRequest
{
public function rules(): array
{
$isCreating = $this->isMethod('post');
return [
'image' => ['sometimes', 'nullable', 'image', 'max:4096'],
'image_url' => ['required_without:image', 'nullable', 'string', 'url', 'max:2048'],
'caption' => ['nullable', 'string', 'max:1000'],
'calories' => ['nullable', 'integer', 'min:0'],
'proteins' => ['nullable', 'numeric', 'min:0'],
'carbs' => ['nullable', 'numeric', 'min:0'],
'fats' => ['nullable', 'numeric', 'min:0'],
'title' => ['required', 'string', 'max:255'],
'eaten_at' => ['required', 'date'],
'title' => [$isCreating ? 'required' : 'sometimes', 'string', 'max:255'],
'eaten_at' => [$isCreating ? 'required' : 'sometimes', 'date'],
'visibility' => ['sometimes', Rule::enum(MealPostVisibility::class)],
];
}
@@ -31,6 +35,7 @@ class MealPostsRequest extends FormRequest
return [
'image.max' => "L'image ne doit pas dépasser 4 Mo.",
'image_url.required_without' => 'Ajoute une image au repas.',
'visibility' => 'Choisis une visibilité valide.',
];
}
}