feat: meal post type
This commit is contained in:
parent
bfe11fea98
commit
c9b51f3225
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum MealPostType: string
|
||||||
|
{
|
||||||
|
case BREAKFAST = 'breakfast';
|
||||||
|
case LUNCH = 'lunch';
|
||||||
|
case DINNER = 'dinner';
|
||||||
|
case BRUNCH = 'brunch';
|
||||||
|
case SNACK = 'snack';
|
||||||
|
case DRINK = 'drink';
|
||||||
|
case SUPPLEMENT = "supplement";
|
||||||
|
case OTHER = "other";
|
||||||
|
}
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use App\Enums\MealPostType;
|
||||||
use App\Enums\MealPostVisibility;
|
use App\Enums\MealPostVisibility;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
@ -22,7 +23,8 @@ class MealPostsRequest extends FormRequest
|
||||||
'fats' => ['nullable', 'numeric', 'min:0'],
|
'fats' => ['nullable', 'numeric', 'min:0'],
|
||||||
'title' => [$isCreating ? 'required' : 'sometimes', 'string', 'max:255'],
|
'title' => [$isCreating ? 'required' : 'sometimes', 'string', 'max:255'],
|
||||||
'eaten_at' => [$isCreating ? 'required' : 'sometimes', 'date'],
|
'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)],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class MealPostsResource extends JsonResource
|
||||||
'fats' => $this->fats,
|
'fats' => $this->fats,
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'visibility' => $this->visibility,
|
'visibility' => $this->visibility,
|
||||||
|
'type' => $this->type,
|
||||||
'eatenAt' => $this->eaten_at,
|
'eatenAt' => $this->eaten_at,
|
||||||
'createdAt' => $this->created_at,
|
'createdAt' => $this->created_at,
|
||||||
'updatedAt' => $this->updated_at,
|
'updatedAt' => $this->updated_at,
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\MealPostType;
|
||||||
use App\Enums\MealPostVisibility;
|
use App\Enums\MealPostVisibility;
|
||||||
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
@ -24,6 +25,7 @@ class MealPosts extends Model
|
||||||
'title',
|
'title',
|
||||||
'eaten_at',
|
'eaten_at',
|
||||||
'visibility',
|
'visibility',
|
||||||
|
'type',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
|
|
@ -40,6 +42,7 @@ class MealPosts extends Model
|
||||||
return [
|
return [
|
||||||
'eaten_at' => 'datetime',
|
'eaten_at' => 'datetime',
|
||||||
'visibility' => MealPostVisibility::class,
|
'visibility' => MealPostVisibility::class,
|
||||||
|
'type' => MealPostType::class
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('meal_posts', function (Blueprint $table) {
|
||||||
|
$table->string("type")->default('breakfast');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('meal_posts', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue