<?php
namespace App\model;
use Illuminate\Database\Eloquent\Model;
class Products extends Model
{
protected $table = 'products';
protected $hidden = [];
protected $appends = ['ProdcutsComments', 'ProdcutsUnit','ShopName','ShopId', 'ShopCityId'];
public function getProdcutsUnitAttribute()
{
$Units = Unit::
where('id', $this->unit)->
get();
return $Units;
}
public function getProdcutsCommentsAttribute()
{
$Productcomments = Productcomment::
where('Shop_Id', $this->id)->
get();
return $Productcomments;
}
public function Shops()
{
// return $this->belongsToMany('\Products', 'ordersprpductlists');
return $this->hasOne('App\model\Shop', 'id', 'shop');
}
public function getShopNameAttribute()
{
//return $this->shop;
$shopId = $this->shop ;
$Shop = Shop ::where('id', $shopId)->first();
if ( $Shop == null ) return 'shop';
else
return
$Shop->name ;
}
public function getShopIdAttribute()
{
//return $this->shop;
$shopId = $this->shop ;
$Shop = Shop ::where('id', $shopId)->first();
if ( $Shop == null ) return 'shop';
else
return
$Shop->id ;
}
public function getShopIdAttribute()
{
//return $this->shop;
$shopId = $this->shop ;
$Shop = Shop ::where('id', $shopId)->first();
if ( $Shop == null ) return '0';
else
return
$Shop->id ;
}
public function getShopCityIdAttribute()
{
//return $this->shop;
$shopId = $this->shop ;
$Shop = Shop ::where('id', $shopId)->first();
if ( $Shop == null ) return 'shop';
else
return
$Shop->city ;
}
}