Recipes/app/Recipe.php

37 lines
905 B
PHP
Raw Permalink Normal View History

<?php
namespace App;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2022-02-07 23:42:52 -06:00
use Carbon\Carbon;
class Recipe extends Model
{
protected $fillable = ['name','user_id','author','servings','serving_size','date_entered','date_modified','description','instructions'];
2022-02-07 23:42:52 -06:00
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);
}
2022-02-07 21:50:25 -06:00
public function user()
{
return $this->belongsTo('App\User');
}
public function ingredients()
{
return $this->hasMany('App\RecipeIngredient');
}
public function categories()
{
return $this->hasMany('App\RecipeCategory');
}
}