66 lines
1.7 KiB
PHP
66 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\NutritionPlanSource;
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class NutritionPlan extends Model
|
|
{
|
|
/** @use HasFactory<\Database\Factories\NutritionPlanFactory> */
|
|
use HasFactory, HasUlids;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'source',
|
|
'formula_version',
|
|
'calories',
|
|
'proteins',
|
|
'carbs',
|
|
'fats',
|
|
'resting_metabolism',
|
|
'maintenance_calories',
|
|
'calorie_adjustment_percent',
|
|
'calculation_details',
|
|
'is_active',
|
|
'effective_from',
|
|
'effective_until',
|
|
];
|
|
|
|
protected $attributes = [
|
|
'is_active' => true,
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'source' => NutritionPlanSource::class,
|
|
'calories' => 'integer',
|
|
'proteins' => 'float',
|
|
'carbs' => 'float',
|
|
'fats' => 'float',
|
|
'resting_metabolism' => 'integer',
|
|
'maintenance_calories' => 'integer',
|
|
'calorie_adjustment_percent' => 'float',
|
|
'calculation_details' => 'array',
|
|
'is_active' => 'boolean',
|
|
'effective_from' => 'immutable_datetime',
|
|
'effective_until' => 'immutable_datetime',
|
|
];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function weeklyReviews(): HasMany
|
|
{
|
|
return $this->hasMany(WeeklyReview::class);
|
|
}
|
|
}
|