currentCompany) { $companyId = Auth::user()->currentCompany->id; session(['current_company_id' => $companyId]); } if ($companyId) { $builder->where("{$model->getTable()}.company_id", $companyId); } else { Log::error('CurrentCompanyScope: No company_id found for user ' . Auth::id()); throw new ModelNotFoundException('CurrentCompanyScope: No company_id set in the session or on the user.'); } } }