<?php

namespace Modules\Order\Models;

use Illuminate\Database\Eloquent\Model;
use Modules\Attribute\Models\Attribute;
use Modules\Product\Models\Product;

class OrderProduct extends Model
{
    public $timestamps = true;
    protected $fillable =
        [
            'count',
            'product_cost',
            'order_id',
            'product_id',
            'product_total',
//            'points',
            'created_at',
            'updated_at'
        ];

    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 order()
    {
        return $this->belongsTo(Order::class)->withTrashed();
    }
    public function product()
    {
        return $this->belongsTo(Product::class)->withTrashed();
    }
    public function mainAttr()
    {
        return $this->belongsTo(Attribute::class, 'main_attribute_id')->withTrashed();
    }
    public function subAttr()
    {
        return $this->belongsTo(Attribute::class, 'sub_attribute_id')->withTrashed();
    }
}
