<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravelista\Comments\Comments\Traits\Comments;


class Subtask extends Model
{
    //

    use Comments;

    protected $table = 'subtasks';

    protected $fillable = array('title', 'description', 'deadline', 'assigned_id', 'user_id', 'status_id', 'task_id');


    public $timestamps = true;


    public function task()
    {
        return $this->belongsTo('App\Task', 'task_id', 'id');

    }

    public function assignedTo()
    {
        return $this->belongsTo('App\User', 'assigned_id', 'id');
    }

    public function createdBy()
    {
        return $this->belongsTo('App\User', 'user_id', 'id');
    }

    public function status(){
            return $this->hasOne( 'App\Status','id','status_id');
    }
    public function  tasktag()
    {
        return $this->belongsTo('App\Tasktag','relation_id','id');
    }

//    public function attachments()
//    {
//        return $this->hasMany('App\Attachment', 'subtask_id', 'id');
//    }

    public function attachments(){
        return $this->belongsToMany('App\Attachment',"attach_subtask")->withPivot('active');
    }

//    public function users(){
//        return $this->belongsToMany('\App\User','menu_task_user')
//            ->withPivot('menu_id','status');
//    }
//    public function menu(){
//        return $this->belongsToMany('\App\Menu','menu_task_user')
//            ->withPivot('user_id','status');
//    }

}
