diff --git a/app/Models/Ingredient.php b/app/Models/Ingredient.php index b6b8934..60946b7 100644 --- a/app/Models/Ingredient.php +++ b/app/Models/Ingredient.php @@ -10,7 +10,7 @@ class Ingredient extends Model use HasFactory; /** - * The attributes that are mass assignable. + * @inheritdoc */ protected array $fillable = [ 'name', diff --git a/app/Models/IngredientAmount.php b/app/Models/IngredientAmount.php index 3c4f933..02d97d0 100644 --- a/app/Models/IngredientAmount.php +++ b/app/Models/IngredientAmount.php @@ -11,13 +11,18 @@ class IngredientAmount extends Model use HasFactory; /** - * The attributes that are mass assignable. + * @inheritdoc */ protected array $fillable = [ 'amount', 'weight', ]; + /** + * @inheritdoc + */ + protected array $with = ['ingredient']; + /** * Get the Ingredient this amount belongs to. */ @@ -31,4 +36,11 @@ class IngredientAmount extends Model public function recipe(): BelongsTo { return $this->belongsTo(Recipe::class); } + + /** + * Get total calories for the ingredient amount. + */ + public function calories(): float { + return $this->ingredient->calories * $this->amount; + } } diff --git a/app/Models/Recipe.php b/app/Models/Recipe.php index 3416da7..6001bfb 100644 --- a/app/Models/Recipe.php +++ b/app/Models/Recipe.php @@ -12,12 +12,17 @@ class Recipe extends Model use HasFactory; /** - * The attributes that are mass assignable. + * @inheritdoc */ protected array $fillable = [ 'name', ]; + /** + * @inheritdoc + */ + protected array $with = ['ingredientAmounts']; + /** * Get the Ingredient Amounts used for this Recipe. */ diff --git a/app/Models/User.php b/app/Models/User.php index 804799b..68a353b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -12,32 +12,26 @@ class User extends Authenticatable use HasFactory, Notifiable; /** - * The attributes that are mass assignable. - * - * @var array + * @inheritdoc */ - protected $fillable = [ + protected array $fillable = [ 'name', 'email', 'password', ]; /** - * The attributes that should be hidden for arrays. - * - * @var array + * @inheritdoc */ - protected $hidden = [ + protected array $hidden = [ 'password', 'remember_token', ]; /** - * The attributes that should be cast to native types. - * - * @var array + * @inheritdoc */ - protected $casts = [ + protected array $casts = [ 'email_verified_at' => 'datetime', ]; }