<?php

namespace App;

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

use Carbon\Carbon;

class Reservations extends Model
{
	use SoftDeletes;

	protected $dates = ['deleted_at','date_start', 'date_end', 'created_at'];
	protected $table = 'reservations';

	protected $fillable = [
		'reference_number',
		'user_id',
    'boat_id',
		'first_name',
		'last_name',
		'telephone',
		'email',
		'date_start',
    'status_id',
		'schedule_id',
		'comments'

	];

	public function user()
	{
		return $this->belongsTo('App\User');
	}

	public function status()
	{
		return $this->belongsTo('App\Status');
	}

	public function boat()
	{
		return $this->belongsTo('App\Boat','boat_id');
	}

  public function schedule()
	{
		return $this->belongsTo('App\Schedule', 'schedule_id');
	}

	public function setDateStartAttribute($date_start){
		$this->attributes['date_start'] = Carbon::parse($date_start);
	}

	public function getDateStartAttribute($date_start){
		// return Carbon::parse($date_start)->format('m/d/Y');
		return Carbon::parse($date_start)->format('d/m/Y');
	}

     public function setCreatedAtAttribute($created_at){
		$this->attributes['created_at'] = Carbon::parse($created_at);
	}

	public function getCreatedAtAttribute($created_at){

		return Carbon::parse($created_at)->format('m/d/Y');
	}

	public function createdAtRealTime(){
		return $this->attributes['created_at'];
	}

	public function getCreated_AtAttribute($created_at){
		return Carbon::parse($created_at)->format('m/d/Y');
	}
}
