HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.shooperm.com/Modules/Product/Entities/Brand.php
<?php

namespace Modules\Product\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Modules\Appearance\Entities\HeaderSliderPanel;
use Modules\FrontendCMS\Entities\HomepageCustomBrand;
use Modules\Menu\Entities\MegaMenuBottomPanel;
use Modules\Menu\Entities\MenuElement;
use Modules\Seller\Entities\SellerProduct;

class Brand extends Model
{
    use \Staudenmeir\EloquentHasManyDeep\HasRelationships;
    protected $table = "brands";
    protected $guarded = ["id"];

    public static function boot()
    {
        parent::boot();
        static::created(function ($brand) {
            $brand->created_by = Auth::user()->id ?? null;
        });

        static::updating(function ($brand) {
            $brand->updated_by = Auth::user()->id ?? null;
        });

        self::created(function ($model) {
            Cache::forget('MegaMenu');
            Cache::forget('HeaderSection');
        });
        self::updated(function ($model) {
            Cache::forget('MegaMenu');
            Cache::forget('HeaderSection');
        });
        self::deleted(function ($model) {
            Cache::forget('MegaMenu');
            Cache::forget('HeaderSection');
        });
    }


    public function products(){
        return $this->hasMany(Product::class,'brand_id','id');
    }

    public function sellerProductsAll(){
        return SellerProduct::where('status',1)->whereHas('product',function($query){
            return $query->where('brand_id',$this->id);
        })->activeSeller()->get();

    }
    public function sellerProducts(){
        return $this->hasManyThrough(SellerProduct::class, Product::class)->activeSeller();
    }

    public function categories(){
        return $this->hasManyDeep(Category::class, 
        [
            Product::class,
            CategoryProduct::class
        ],
        [
            'brand_id', // Foreign key on the "users" table.
            'category_id',     // Foreign key on the "comments" table.
            'id'    // Foreign key on the "posts" table.
        ],
        [  
            'id',               // Local key on "tool_groups" table
            'brand_id',                // Local key on "tools" table
            'category_id',          // Local key on pivot table
        ]
        );
    }
    
    public function getMenuElementsAttribute(){
        return MenuElement::where('type', 'brand')->where('element_id', $this->id)->get();
    }

    public function MenuBottomPanel(){
        return $this->hasMany(MegaMenuBottomPanel::class,'brand_id', 'id');
    }

    public function getSildersAttribute(){
        return HeaderSliderPanel::where('data_type','brand')->where('data_id', $this->id)->get();
    }

    public function homepageCustomBrands(){
        return $this->hasMany(HomepageCustomBrand::class, 'brand_id', 'id');
    }

    //for api
    public function getAllProductsAttribute(){
        return SellerProduct::with('product')->whereHas('product', function($query){
            return $query->where('brand_id', $this->id);
        })->activeSeller()->paginate(10);
    }
    
    protected static function factory(){
        return \Modules\Product\Database\factories\BrandFactory::new();
    }
}