<?php

namespace App;

use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Model;

class OrderCommodity extends Model
{
    protected $fillable = [
        'id', 'order_id','commodity_id', 'amount','wms_ptltaskid','location'
    ];
    protected $appends=['barcode','name','sku'];
    public function order(){
        return $this->belongsTo('App\Order', 'order_id','id');
    }
    public function commodity(){
        return $this->hasOne('\App\Commodity','id','commodity_id');
    }
    public function getBarcodeAttribute(){
        $commodity=$this->commodity()->first();
        if($commodity)return $commodity['barcode'];
        return '';
    }
    public function getNameAttribute(){
        $commodity=$this->commodity()->first();
        if($commodity)return $commodity['name'];
        return '';
    }
    public function getSkuAttribute(){
        $commodity=$this->commodity()->first();
        if($commodity)return $commodity['sku'];
        return '';
    }
}
