From 983a636e8ef767832a4c37897e4f51b35fbfd5c5 Mon Sep 17 00:00:00 2001 From: Sander Muller Date: Mon, 28 Apr 2025 16:01:42 +0200 Subject: [PATCH] Support viewing comments as guest --- resources/views/comments.blade.php | 4 ++-- src/Actions/CommentsAction.php | 2 +- src/Infolists/Components/CommentsEntry.php | 2 +- src/Livewire/CommentsComponent.php | 6 +++--- src/Tables/Actions/CommentsAction.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/resources/views/comments.blade.php b/resources/views/comments.blade.php index ce6c2f3..9941392 100644 --- a/resources/views/comments.blade.php +++ b/resources/views/comments.blade.php @@ -1,5 +1,5 @@
- @if (auth()->user()->can('create', \Parallax\FilamentComments\Models\FilamentComment::class)) + @if (auth()->user()?->can('create', \Parallax\FilamentComments\Models\FilamentComment::class))
{{ $this->form }} @@ -33,7 +33,7 @@
- @if (auth()->user()->can('delete', $comment)) + @if (auth()->user()?->can('delete', $comment))
modalWidth(MaxWidth::Medium) ->modalSubmitAction(false) ->modalCancelAction(false) - ->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model'))); + ->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false); } } diff --git a/src/Infolists/Components/CommentsEntry.php b/src/Infolists/Components/CommentsEntry.php index ab4d7c4..16d1d33 100644 --- a/src/Infolists/Components/CommentsEntry.php +++ b/src/Infolists/Components/CommentsEntry.php @@ -13,6 +13,6 @@ protected function setUp(): void { parent::setUp(); - $this->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model'))); + $this->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false); } } diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index 021999d..1bd3786 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -27,7 +27,7 @@ public function mount(): void public function form(Form $form): Form { - if (!auth()->user()->can('create', config('filament-comments.comment_model'))) { + if (!auth()->user()?->can('create', config('filament-comments.comment_model'))) { return $form; } @@ -55,7 +55,7 @@ public function form(Form $form): Form public function create(): void { - if (!auth()->user()->can('create', config('filament-comments.comment_model'))) { + if (!auth()->user()?->can('create', config('filament-comments.comment_model'))) { return; } @@ -85,7 +85,7 @@ public function delete(int $id): void return; } - if (!auth()->user()->can('delete', $comment)) { + if (!auth()->user()?->can('delete', $comment)) { return; } diff --git a/src/Tables/Actions/CommentsAction.php b/src/Tables/Actions/CommentsAction.php index 9b60967..62bf850 100644 --- a/src/Tables/Actions/CommentsAction.php +++ b/src/Tables/Actions/CommentsAction.php @@ -30,6 +30,6 @@ protected function setUp(): void ->modalWidth(MaxWidth::Medium) ->modalSubmitAction(false) ->modalCancelAction(false) - ->visible(fn (): bool => auth()->user()->can('viewAny', config('filament-comments.comment_model'))); + ->visible(fn (): bool => auth()->user()?->can('viewAny', config('filament-comments.comment_model')) ?? false); } }