2019-12-15 15:45:22 +01:00
|
|
|
<?php
|
|
|
|
|
2020-01-06 17:14:54 +01:00
|
|
|
namespace App\Models;
|
2019-12-15 15:45:22 +01:00
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2020-01-06 17:14:54 +01:00
|
|
|
use App\Helpers\NutritionCalculator;
|
2019-12-15 15:45:22 +01:00
|
|
|
|
|
|
|
class Recipe extends Model
|
|
|
|
{
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
|
|
|
|
protected $with = ['steps', 'ingredients'];
|
|
|
|
|
|
|
|
protected $hidden = ['created_at', 'updated_at'];
|
|
|
|
|
2020-01-06 17:14:54 +01:00
|
|
|
protected $appends = ['nutrition'];
|
|
|
|
|
2019-12-15 15:45:22 +01:00
|
|
|
public function steps()
|
|
|
|
{
|
|
|
|
return $this->hasMany(RecipeStep::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ingredients()
|
|
|
|
{
|
|
|
|
return $this->hasMany(RecipeProduct::class);
|
|
|
|
}
|
2020-01-06 17:14:54 +01:00
|
|
|
|
|
|
|
public function getNutritionAttribute()
|
|
|
|
{
|
|
|
|
return NutritionCalculator::calculateNutritionForRecipe($this->ingredients);
|
|
|
|
}
|
2019-12-15 15:45:22 +01:00
|
|
|
}
|