MOON
Server: Apache
System: Linux 101-53-147-124.cprapid.com 4.18.0-553.121.1.el8_10.x86_64 #1 SMP Thu Apr 30 09:06:34 EDT 2026 x86_64
User: clientsoftwares (1005)
PHP: 8.2.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: /home/clientsoftwares/www/crm.clientsoftwares.com/app/Product.php
<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\MediaLibrary\HasMedia\HasMediaTrait;
use Spatie\MediaLibrary\HasMedia\HasMedia;

/**
 * Class Product
 *
 * @package App
 * @property string $name
 * @property string $product_code
 * @property decimal $actual_price
 * @property decimal $sale_price
 * @property string $ware_house
 * @property text $description
 * @property integer $stock_quantity
 * @property integer $alert_quantity
 * @property string $thumbnail
 * @property string $hsn_sac_code
 * @property string $product_size
 * @property string $product_weight
 * @property string $brand
*/
class Product extends Model implements HasMedia
{
    use SoftDeletes;
    use HasMediaTrait;

    protected $fillable = ['name', 'product_code', 'actual_price', 'sale_price', 'description', 'stock_quantity', 'alert_quantity', 'thumbnail', 'hsn_sac_code', 'product_size', 'product_weight', 'ware_house_id', 'brand_id', 'tax_id', 'discount_id', 'measurement_unit', 'product_status', 'excerpt', 'prices', 'prices_available'];
    protected $hidden = [];
    public static $searchable = [ 'name', 'product_code', 'description'    ];
    
    public static $enum_product_status = ["Active" => "Active", "Inactive" => "Inactive", 'Damaged' => 'Damaged'];

    public static function boot()
    {
        parent::boot();
        // ob_start();
        Product::observe(new \App\Observers\UserActionsObserver);

        static::addGlobalScope(new \App\Scopes\DefaultOrderScope);
    }
    /**
     * Set attribute to money format
     * @param $input
     */
    public function setActualPriceAttribute($input)
    {
        $this->attributes['actual_price'] = $input ? $input : null;
    }

    /**
     * Set attribute to money format
     * @param $input
     */
    public function setSalePriceAttribute($input)
    {
        $this->attributes['sale_price'] = $input ? $input : null;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setWareHouseIdAttribute($input)
    {
        $this->attributes['ware_house_id'] = $input ? $input : null;
    }

    /**
     * Set attribute to money format
     * @param $input
     */
    public function setStockQuantityAttribute($input)
    {
        $this->attributes['stock_quantity'] = $input ? $input : null;
    }

    /**
     * Set attribute to money format
     * @param $input
     */
    public function setAlertQuantityAttribute($input)
    {
        $this->attributes['alert_quantity'] = $input ? $input : null;
    }

    /**
     * Set to null if empty
     * @param $input
     */
    public function setBrandIdAttribute($input)
    {
        $this->attributes['brand_id'] = $input ? $input : null;
    }
    
    public function category()
    {
        return $this->belongsToMany(ProductCategory::class, 'product_product_category');
    }
    
    public function product_currency()
    {
        return $this->belongsToMany(Currency::class, 'product_currency');
    }
    
    public function ware_house()
    {
        return $this->belongsTo(Warehouse::class, 'ware_house_id')->withTrashed();
    }
    
    public function brand()
    {
        return $this->belongsTo(Brand::class, 'brand_id')->withTrashed();
    }

    public function tax()
    {
        return $this->belongsTo(Tax::class, 'tax_id')->withTrashed();
    }

    public function discount()
    {
        return $this->belongsTo(Discount::class, 'discount_id')->withTrashed();
    }

    public function measurement()
    {
        return $this->belongsTo(MeasurementUnit::class, 'measurement_unit')->withTrashed();
    }
    
}