app\models\EntityModel::scopeScope PHP Method

scopeScope() public method

public scopeScope ( $query, boolean $publicId = false, boolean $accountId = false ) : mixed
$query
$publicId boolean
$accountId boolean
return mixed
    public function scopeScope($query, $publicId = false, $accountId = false)
    {
        if (!$accountId) {
            $accountId = Auth::user()->account_id;
        }
        $query->where($this->getTable() . '.account_id', '=', $accountId);
        if ($publicId) {
            if (is_array($publicId)) {
                $query->whereIn('public_id', $publicId);
            } else {
                $query->wherePublicId($publicId);
            }
        }
        if (Auth::check() && !Auth::user()->hasPermission('view_all') && $this->getEntityType() != ENTITY_TAX_RATE) {
            $query->where(Utils::pluralizeEntityType($this->getEntityType()) . '.user_id', '=', Auth::user()->id);
        }
        return $query;
    }