<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Dimsav\Translatable\Translatable;

class Product extends Model
{
    use Translatable;

    protected $table="product";
    protected $fillable = [
        'product_code', 'product_price', 'product_cost',
        'product_weight', 'product_stock', 'product_min_quantity',
        'product_category', 'product_margin', 'production_time', 'sort'
    ];

    public $translationModel = 'App\ProductLocale';
    public $translatedAttributes = ['product_name', 'product_content', 'product_alt'];

    public function getProductNameAttribute($value)
    {
        return ucfirst($value);
    }

    public function locales(){
      return $this->hasMany('App\ProductLocale');
    }

    public function quantities()
    {
    	return $this->hasMany('App\ProductQuantity');
    }
    public function category()
    {
    	return $this->belongsTo('App\Category', 'product_category');
    }
    public function details()
    {
        return $this->hasMany('App\ProductDetail', 'detail_code', 'product_code');
    }

    // public function getProductMarginAttribute($value)
}
