<?php

namespace App\Models;

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

class Order extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'token','date','status','start_time','end_time','length_time','count_members','total','user_id','room_id','table_number_id','reservation_id'
    ];

    public function getShowDateAttribute()
    {
        $date = date('d',strtotime($this->date)) . ' ';
        $date .= __(date('F',strtotime($this->date))) . ' ';
        $date .= date('Y',strtotime($this->date));
        return $date;
    }

    public function user()
    {
        return $this->belongsTo(User::class)->withTrashed();
    }

    public function room()
    {
        return $this->belongsTo(Room::class)->withTrashed();
    }

    public function reservation()
    {
        return $this->belongsTo(Reservation::class)->withTrashed();
    }

    public function table()
    {
        return $this->belongsTo(TableNumber::class,'table_number_id')->withTrashed();
    }
    public function payment()
    {
        return $this->hasOne(OrderPayment::class);
    }
    public function products()
    {
        return $this->hasMany(OrderProduct::class);
    }

}
