user(); if (!$user) return; // Skip global scope for shop-owner when not inside a branch if ($user->role === 'shop-owner' && !$user->active_branch_id) { return; } if ($user->active_branch_id) { $builder->where($model->getTable() . '.branch_id', $user->active_branch_id); return; } // Otherwise fall back to user's fixed branch (for staff) if (!is_null($user->branch_id)) { $builder->where($model->getTable() . '.branch_id', $user->branch_id); } } }