<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Te7aHoudini\LaravelTrix\Traits\HasTrixRichText;
use App\Traits\ModelTimeFormat;

use App\Traits\ModelLogChanging;

class Tutorial extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;
    use HasTrixRichText;
    protected $guarded=[];

    protected $fillable=[
        'owner_id','name','type'
    ];
    protected $appends=[
        'owner_name'
    ];


    public function owner(){
        return $this->belongsTo('App\Owner','owner_id','id');
    }
    public function trixRichText(){
        return $this->belongsTo('Te7aHoudini\LaravelTrix\Models\TrixRichText','id','model_id');
    }
    public function trixAttachments()
    {
        return $this->hasMany('Te7aHoudini\LaravelTrix\Models\TrixAttachment','attachable_id','id');
    }
    public function processes(){
        return $this->belongsToMany('App\Process');
    }

    public function getOwnerNameAttribute()
    {
        return $this['owner']? $this['owner']['name']:null;
    }
}
