Current File : //home/tradevaly/demo.tradevaly.com.bd/app/Models/Product.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Product extends Model
{
    use HasFactory;
    //use SoftDeletes;


    protected $fillable = [

        'created_user_id', 'modified_user_id', 'deleted_user_id', 'company_id', 'is_service', 'show_type', 'is_trending', 'product_name', 'country_id', 'first_step_cat_id', 'second_step_cat_id',

        'short_description', 'description', 'unit_id', 'size_id', 'color_id', 'feature_product_image', 'galleries', 'youtube_video', 

        'catelog_file', 'catelog_showable', 'tds_file', 'tds_showable', ' brand_ids', 'tentitive_delivery_days', 'status'
        
    ];

   
    
   public function productCategoryDetails()
    {
        return $this->hasMany('App\Models\ProductCategoryDetail');
    }

    public function productPrice()
    {
        return $this->hasMany('App\Models\ProductPrice');
    }

    public function productInventory()
    {
        return $this->hasMany('App\Models\ProductInventory');
    }


    public function company()
    {
        return $this->belongsTo('App\Models\Company');
    }




    

    protected function getProductList($conditions  = [])
    {   
        $data = Product::where('status', 1)->pluck('product_name', 'id')->toArray();

        return $data;
    }


    protected  function getProductWithOthers( $selectProduct = [], $productCondition = [], $productLimit, $selectInventory = [], $inventoryCondition = [], $selectPrice = [], $priceCondition = [], $priceOrderBy = 'asc',  $inventoryOrderBy = 'asc', $inventoryLimit = '')
    {   
        
        //dd($productLimit);
        
        $data = Product::select($selectProduct)
            ->where($productCondition)
            ->orderBy('id', 'desc')
            ->limit($productLimit)
                ->with (['productPrice' => function($mm) use ($selectPrice, $priceCondition, $priceOrderBy){
                        return $mm->select($selectPrice)
                        ->where($priceCondition)
                        ->orderBy('id', 'desc');
                }])
                ->with (['productInventory' => function($mm) use ($selectInventory, $inventoryCondition, $inventoryOrderBy){
                        return $mm->select($selectInventory)
                        ->where($inventoryCondition)
                        ->orderBy('id', 'desc');
                }]);



        return $data;
    }


    

    

}