👁 View: Shop.php
Path: /home/thiqat5/dex.thiqatech.com/model/Shop.php
Size: 1.63 KB · Modified: 2021-11-03 20:28:12 · Perm: 0644 · Writable
<?php

namespace App\model;

use Illuminate\Database\Eloquent\Model;

class Shop extends Model
{  // protected $visible = ['name', 'Phone'];
    //


    protected $hidden = ['city','Cities','Dealers','dealer_id'];
    protected $appends = ['ShopCity','Dealer','ProductCount','ShopsComments','SalesCount','OrdersCount'];


   
    public function getSalesCountAttribute()
    {
        $Productcomments =  Productcomment:: 
        where('shop_id', $this->id)->
        get();
        return 5000;
    
       
    }

    public function getOrdersCountAttribute()
    {
        $Productcomments =  Productcomment:: 
        where('shop_id', $this->id)->
        get();
        return 5;
    
       
    }

    public function getShopsCommentsAttribute()
    {
        $Productcomments =  Productcomment:: 
        where('shop_id', $this->id)->
        get();
        return $Productcomments;
    
       
    }
    public function Cities()
    {
       
        return $this->hasOne('App\model\Cities' ,'id', 'city');
    //    ->select(app('App\model\Cities')->getTable().'.name');
       
    }  

    public function getShopCityAttribute()
    {
        return $this->Cities;
       
    }

    public function getProductCountAttribute()
    {
        $Products = Products:: where('shop', $this->id)->get();
        return count($Products) ;

    }
    
    
    public function Dealers()
    {
       
        return $this->hasOne('App\model\Customer' ,'id', 'dealer_id');
    //   ->select(app('App\model\Customer')->getTable().'.first_name','.last_name');
       
    }  

    public function getDealerAttribute()
    {
        return $this->Dealers;
       
    }
}