resolveOrganisationId(); if ($id === null) { return; } $column = $model->organisationScopeColumn ?? 'organisation_id'; match ($column) { 'organisation_id' => $builder->where($model->getTable() . '.organisation_id', $id), 'event_id' => $builder->whereIn( $model->getTable() . '.event_id', Event::withoutGlobalScope(self::class) ->where('organisation_id', $id) ->select('id') ), 'festival_section_id' => $builder->whereIn( $model->getTable() . '.festival_section_id', \App\Models\FestivalSection::withoutGlobalScope(self::class) ->whereIn('event_id', Event::withoutGlobalScope(self::class) ->where('organisation_id', $id) ->select('id')) ->select('id') ), default => null, }; } private function resolveOrganisationId(): ?string { if ($this->organisationId !== null) { return $this->organisationId; } $route = request()->route(); if ($route === null) { return null; } $org = $route->parameter('organisation'); if ($org instanceof \App\Models\Organisation) { return $org->id; } if (is_string($org) && $org !== '') { return $org; } // Fall back to the event's organisation if we're on an event route $event = $route->parameter('event'); if ($event instanceof Event) { return $event->organisation_id; } return null; } }