mirror of https://github.com/kcal-app/kcal.git
82 lines
2.3 KiB
PHP
82 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Support\Nutrients;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/**
|
|
* App\Models\Goal
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property \datetime|null $from
|
|
* @property \datetime|null $to
|
|
* @property string $goal
|
|
* @property float $amount
|
|
* @property \Illuminate\Support\Carbon|null $created_at
|
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
|
* @property-read \App\Models\User $user
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal newModelQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal newQuery()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal query()
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereAmount($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereCreatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereFrom($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereGoal($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereId($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereTo($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUpdatedAt($value)
|
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value)
|
|
* @mixin \Eloquent
|
|
*/
|
|
final class Goal extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
protected $fillable = [
|
|
'from',
|
|
'to',
|
|
'goal',
|
|
'amount',
|
|
];
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
protected $casts = [
|
|
'from' => 'datetime:Y-m-d',
|
|
'to' => 'datetime:Y-m-d',
|
|
'amount' => 'float',
|
|
];
|
|
|
|
/**
|
|
* Get the User this goal belongs to.
|
|
*/
|
|
public function user(): BelongsTo {
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* Get options for the "goal" column.
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getGoalOptions(): array {
|
|
$options = [];
|
|
foreach (Nutrients::$all as $nutrient) {
|
|
$key = "{$nutrient['value']}_per_day";
|
|
$options[$key] = [
|
|
'value' => $key,
|
|
'label' => "{$nutrient['value']} per day",
|
|
];
|
|
}
|
|
return $options;
|
|
}
|
|
}
|