<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelTimeFormat;

use App\Traits\ModelLogChanging;

class StoreItem extends Model
{
    use ModelLogChanging;

    use ModelTimeFormat;
    protected $fillable=[
        'store_id','asn_line_code','name',
        'sku','barcode','depository_id','amount','quality','status','commodity_id'
    ];
    protected $appends=[
        'store_asn_code',
        'depository_name'
    ];

    public function depository(){
        return $this->belongsTo('App\Depository','depository_id','id');
    }
    public function store(){
        return $this->belongsTo('App\Store','store_id','id');
    }
    public function commodity(){
        return $this->hasOne('App\Commodity','id','commodity_id');
    }


    public function getStoreASNCodeAttribute()
    {
        return $this['store']?$this['store']['asn_code']:null;
    }
    public function getDepositoryNameAttribute()
    {
        return $this['depository']?$this['depository']['name']:null;
    }
}
