<?php

namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Recipe extends Model
{
    protected $fillable = ['name','user_id','author','servings','serving_size','date_entered','date_modified','description','instructions'];
    protected $dates = ['date_entered','date_modified'];

    public function setDateEnteredAttribute($value){
        $this->attributes['date_entered']=Carbon::parse($value);
    }

    public function setDateModifiedAttribute($value){
        $this->attributes['date_modified']=Carbon::parse($value);
    }

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function ingredients()
    {
        return $this->hasMany('App\RecipeIngredient');
    }

    public function categories()
    {
        return $this->hasMany('App\RecipeCategory');
    }
}
