diff --git a/app/Enums/MealPostType.php b/app/Enums/MealPostType.php new file mode 100644 index 0000000..b76340a --- /dev/null +++ b/app/Enums/MealPostType.php @@ -0,0 +1,15 @@ + ['nullable', 'numeric', 'min:0'], 'title' => [$isCreating ? 'required' : 'sometimes', 'string', 'max:255'], 'eaten_at' => [$isCreating ? 'required' : 'sometimes', 'date'], - 'visibility' => ['sometimes', Rule::enum(MealPostVisibility::class)], + 'type' => [$isCreating ? 'required' : 'sometimes', Rule::enum(MealPostType::class)], + 'visibility' => [$isCreating ? 'required' :'sometimes', Rule::enum(MealPostVisibility::class)], ]; } diff --git a/app/Http/Resources/MealPostsResource.php b/app/Http/Resources/MealPostsResource.php index d52d399..ffbe0f1 100644 --- a/app/Http/Resources/MealPostsResource.php +++ b/app/Http/Resources/MealPostsResource.php @@ -25,6 +25,7 @@ class MealPostsResource extends JsonResource 'fats' => $this->fats, 'title' => $this->title, 'visibility' => $this->visibility, + 'type' => $this->type, 'eatenAt' => $this->eaten_at, 'createdAt' => $this->created_at, 'updatedAt' => $this->updated_at, diff --git a/app/Models/MealPosts.php b/app/Models/MealPosts.php index c5769c2..faeb47d 100644 --- a/app/Models/MealPosts.php +++ b/app/Models/MealPosts.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\MealPostType; use App\Enums\MealPostVisibility; use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -24,6 +25,7 @@ class MealPosts extends Model 'title', 'eaten_at', 'visibility', + 'type', ]; protected $attributes = [ @@ -40,6 +42,7 @@ class MealPosts extends Model return [ 'eaten_at' => 'datetime', 'visibility' => MealPostVisibility::class, + 'type' => MealPostType::class ]; } } diff --git a/database/migrations/2026_05_17_171607_add_type_to_meal_posts.php b/database/migrations/2026_05_17_171607_add_type_to_meal_posts.php new file mode 100644 index 0000000..f9aa042 --- /dev/null +++ b/database/migrations/2026_05_17_171607_add_type_to_meal_posts.php @@ -0,0 +1,28 @@ +string("type")->default('breakfast'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('meal_posts', function (Blueprint $table) { + $table->dropColumn('type'); + }); + } +};