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/public_html/stocky.clientsoftwares.com/app/Scopes/CompanyScope.php
<?php

namespace App\Scopes;

use App\Classes\Common;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Schema;

class CompanyScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {

        // When user is logged in
        // auth('api')->user() do not work in apply so we have use auth()->check()
        if (app_type() == 'saas' && auth('api')->check() && Schema::hasColumn($model->getTable(), 'company_id')) {
            $company = company();

            // company scope will not be applied to global company(superadmin company)
            if ($company && !$company->is_global) {
                $builder->where($model->getTable() . '.company_id', '=', Common::getIdFromHash($company->xid));
            }
        } else if (app_type() == 'non-saas' && auth('api')->check() && Schema::hasColumn($model->getTable(), 'company_id')) {
            $company = company();

            $builder->where($model->getTable() . '.company_id', '=', Common::getIdFromHash($company->xid));
        }
    }
}