<?php

namespace App;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelTimeFormat;

use App\Traits\ModelLogChanging;

class ProcessDailyParticipant extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;
    protected $fillable=[
        'process_daily_id','user_id','started_at','ended_at','hour_price',
        'hour_count','unit_price','unit_count','dinner_duration','remark','status'
    ];
    protected $appends=[
        'user_detail_full_name',
        'process_daily_date',
    ];
    protected $casts = [
        'started_at' => 'datetime:H:i',
        'ended_at' => 'datetime:H:i',
    ];

    public function user_detail(){
        return $this->belongsTo('App\UserDetail','user_id','user_id');
    }
    public function processDaily(){
        return $this->belongsTo('App\ProcessDaily','process_daily_id','id');
    }
    public function userLabor(){
        return $this->belongsTo('App\UserLabor','user_id','user_id');
    }


    public function getUserDetailFullNameAttribute()
    {
        return $this['user_detail']?$this['user_detail']['full_name']:null;
    }
    public function getProcessDailyDateAttribute()
    {
        return $this['processDaily'] ? $this['processDaily']['date'] : null;
    }
}
