<?php

namespace Modules\ChipOrder\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Modules\Address\Models\Address;
use Modules\User\Models\User;

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

    protected $fillable =
        [
            'total',
            'tax_cost',
            'status',
            'shipping_cost',
            'address_id',
            'user_id',
        ];

    public function getDateAttribute()
    {
        $date = date('d', strtotime($this->created_at));
        $date .= ' ' . __('web.monthes.' . date('m', strtotime($this->created_at)));
        $date .= ' ' . date('Y', strtotime($this->created_at));
        return $date;
    }

    public function address()
    {
        return $this->belongsTo(Address::class, 'address_id')->withTrashed();
    }

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

    public function products()
    {
        return $this->hasMany(ChipOrderProduct::class);
    }

}
