Server : Apache System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64 User : vapecompany ( 2719) PHP Version : 7.4.33 Disable Function : NONE Directory : /home/vapecompany/demo.vapecompany.com.bd/app/Models/ |
Upload File : |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use App\Models\ChalanDetails; use App\Models\Barcode; class Category extends Model { use HasFactory; protected $primaryKey ='category_id'; public function submenu(){ return $this->where('parent_id',$this->category_id)->get(); } public function child(){ return $this->hasMany(Category::class, 'parent_id', 'category_id'); } public function product() { return $this->hasMany('App\Models\Product','category_id'); } // public function products() { // return $this->hasManyThrough(Product::class, Category::class, 'parent_id', 'category_id', 'product_id'); // } public function sumChanalan(){ return ChalanDetails::leftJoin('products', 'chalan_details.product_id', '=', 'products.product_id') ->leftJoin('categories', 'products.category_id', '=', 'categories.category_id')->where('categories.category_id',$this->category_id)->sum('chalan_details.product_quantity'); } public function sumBarcode(){ return Barcode::leftJoin('products', 'barcodes.product_id', '=', 'products.product_id') ->leftJoin('categories', 'products.category_id', '=', 'categories.category_id')->where('categories.category_id',$this->category_id)->sum('barcodes.quantity'); } }