<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Message extends Model
{
    
	use SoftDeletes;
	
	public function company()
	{
		return $this->belongsTo('App\Company');
	}
	
	public function employee()
	{
		return $this->belongsTo('App\Employee')->withTrashed();
	}
	
	public function customer()
	{
		return $this->belongsTo('App\Customer')->withTrashed();
	}
	
	protected $casts = [
		'send_to' => 'array',
		'attachments' => 'array'
	];
	
	protected $hidden = ['deleted_at'];
	
	protected $with = ['employee'];
	
	protected $appends = ['created_at_formatted'];
	
	public function getCreatedAtFormattedAttribute()
    {
		if (isset($this->attributes['created_at'])) {
			return date('m/d/Y h:i A', strtotime($this->attributes['created_at']));
		}
        return null;
    }
	
}
