sortBy === $column) { $this->sortDir = $this->sortDir === 'asc' ? 'desc' : 'asc'; } else { $this->sortBy = $column; $this->sortDir = 'asc'; } $this->resetPage(); } public function updatedSearch(): void { $this->resetPage(); } public function updatedStatusFilter(): void { $this->resetPage(); } public function updatedCompanyFilter(): void { $this->resetPage(); } public function submitForReview(int $id): void { $pr = $this->findMyPR($id); if (! $pr) { return; } try { app(PressReleaseService::class)->submitForReview($pr); session()->flash('success', __('Pressemitteilung zur Prüfung eingereicht.')); } catch (BlacklistViolationException $e) { session()->flash('error', __('Pressemitteilung wurde automatisch abgelehnt: unzulässiges Wort ":word".', ['word' => $e->word])); } catch (\LogicException $e) { session()->flash('error', $e->getMessage()); } } public function with(): array { $userId = auth()->id(); $context = app(CustomerCompanyContext::class); $selectedCompanyId = $context->selectedCompanyId(auth()->user()); $prs = PressRelease::withoutGlobalScopes() ->where('user_id', $userId) ->with('company:id,name') ->when($selectedCompanyId !== null, fn ($q) => $q->where('company_id', $selectedCompanyId)) ->when($selectedCompanyId === null && $this->companyFilter === 'assigned', fn ($q) => $q->whereNotNull('company_id')) ->when($selectedCompanyId === null && $this->companyFilter === 'unassigned', fn ($q) => $q->whereNull('company_id')) ->when(filled($this->search), function ($q): void { $term = $this->search; $q->where('title', 'like', '%'.$term.'%'); }) ->when($this->statusFilter !== 'all', fn ($q) => $q->where('status', $this->statusFilter)) ->orderBy(in_array($this->sortBy, ['title', 'status', 'created_at']) ? $this->sortBy : 'created_at', $this->sortDir) ->paginate(100); return [ 'pressReleases' => $prs, 'statusOptions' => PressReleaseStatus::cases(), 'selectedCompany' => $context->selectedCompany(auth()->user()), 'hasGlobalCompanyContext' => $selectedCompanyId === null, ]; } private function findMyPR(int $id): ?PressRelease { return PressRelease::withoutGlobalScopes() ->where('id', $id) ->where('user_id', auth()->id()) ->first(); } }; ?>
{{ $pr->title }}