ClearBowl/api/app/Models/Recipe.php

33 lines
652 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Helpers\NutritionCalculator;
class Recipe extends Model
{
protected $guarded = ['id'];
protected $with = ['steps', 'ingredients'];
protected $hidden = ['created_at', 'updated_at'];
protected $appends = ['nutrition'];
public function steps()
{
return $this->hasMany(RecipeStep::class);
}
public function ingredients()
{
return $this->hasMany(RecipeProduct::class);
}
public function getNutritionAttribute()
{
return NutritionCalculator::calculateNutritionForProducts($this->ingredients);
}
}