From d01fad070fd1af48be8da8eccf18b1b23788c695 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Tue, 25 Feb 2025 12:06:25 +0100 Subject: [PATCH 1/9] feat: allow user to select other users to be notified via Filament database notifications --- config/filament-comments.php | 5 +++ resources/lang/de/filament-comments.php | 4 ++ resources/lang/en/filament-comments.php | 4 +- resources/lang/fa/filament-comments.php | 4 ++ resources/lang/fr/filament-comments.php | 4 ++ resources/lang/it/filament-comments.php | 4 ++ resources/lang/nl/filament-comments.php | 6 ++- resources/lang/no/filament-comments.php | 4 ++ resources/lang/pt_BR/filament-comments.php | 4 ++ resources/lang/ru/filament-comments.php | 4 ++ resources/lang/uk/filament-comments.php | 4 ++ src/Livewire/CommentsComponent.php | 45 +++++++++++++++++++--- 12 files changed, 85 insertions(+), 7 deletions(-) diff --git a/config/filament-comments.php b/config/filament-comments.php index 286b622..6283390 100644 --- a/config/filament-comments.php +++ b/config/filament-comments.php @@ -56,6 +56,11 @@ 'undo', ], + /* + * Allow user to select other users to be notified via Filament database notifications. + */ + 'notify_users' => true, + /* * The attribute used to display the user's name. */ diff --git a/resources/lang/de/filament-comments.php b/resources/lang/de/filament-comments.php index bcc2888..e2aa441 100644 --- a/resources/lang/de/filament-comments.php +++ b/resources/lang/de/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Kommentar gelöscht.', 'modal.heading' => 'Kommentare', + + 'notify_users.placeholder' => 'Benutzer auswählen, die benachrichtigt werden sollen...', + 'notify_users.notification_title' => 'Neuer Kommentar von :user', + 'notify_users.notification_action' => 'Datensatz anzeigen', ]; diff --git a/resources/lang/en/filament-comments.php b/resources/lang/en/filament-comments.php index 8a29d25..c2d905a 100644 --- a/resources/lang/en/filament-comments.php +++ b/resources/lang/en/filament-comments.php @@ -11,5 +11,7 @@ 'modal.heading' => 'Comments', - 'comments.delete.tooltip' => 'Delete comment' + 'notify_users.placeholder' => 'Select users to notify...', + 'notify_users.notification_title' => 'New comment from :user', + 'notify_users.notification_action' => 'View record', ]; diff --git a/resources/lang/fa/filament-comments.php b/resources/lang/fa/filament-comments.php index 3c0caa5..16f5438 100644 --- a/resources/lang/fa/filament-comments.php +++ b/resources/lang/fa/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'نظر حذف شد.', 'modal.heading' => 'نظرات', + + 'notify_users.placeholder' => 'کاربرانی را انتخاب کنید که مایل به اطلاع رسانی هستند...', + 'notify_users.notification_title' => 'نظر جدید از :user', + 'notify_users.notification_action' => 'مشاهده رکورد', ]; diff --git a/resources/lang/fr/filament-comments.php b/resources/lang/fr/filament-comments.php index 132ee27..6020a97 100644 --- a/resources/lang/fr/filament-comments.php +++ b/resources/lang/fr/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Commentaire supprimé.', 'modal.heading' => 'Commentaires', + + 'notify_users.placeholder' => 'Sélectionner les utilisateurs à notifier...', + 'notify_users.notification_title' => 'Nouveau commentaire de :user', + 'notify_users.notification_action' => 'Voir l\'enregistrement', ]; diff --git a/resources/lang/it/filament-comments.php b/resources/lang/it/filament-comments.php index b635622..0b760de 100644 --- a/resources/lang/it/filament-comments.php +++ b/resources/lang/it/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Commento cancellato.', 'modal.heading' => 'Commenti', + + 'notify_users.placeholder' => 'Seleziona utenti da notificare...', + 'notify_users.notification_title' => 'Nuovo commento da :user', + 'notify_users.notification_action' => 'Visualizza record', ]; diff --git a/resources/lang/nl/filament-comments.php b/resources/lang/nl/filament-comments.php index df5a59f..3ccb537 100644 --- a/resources/lang/nl/filament-comments.php +++ b/resources/lang/nl/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Reactie verwijderd.', 'modal.heading' => 'Reacties', -]; \ No newline at end of file + + 'notify_users.placeholder' => 'Selecteer gebruikers om op de hoogte te stellen...', + 'notify_users.notification_title' => 'Nieuwe reactie van :user', + 'notify_users.notification_action' => 'Bekijk record', +]; diff --git a/resources/lang/no/filament-comments.php b/resources/lang/no/filament-comments.php index b33980c..e1241c6 100644 --- a/resources/lang/no/filament-comments.php +++ b/resources/lang/no/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Kommentar slettet.', 'modal.heading' => 'Kommentarer', + + 'notify_users.placeholder' => 'Velg brukere som skal varsles...', + 'notify_users.notification_title' => 'Ny kommentar fra :user', + 'notify_users.notification_action' => 'Se post', ]; diff --git a/resources/lang/pt_BR/filament-comments.php b/resources/lang/pt_BR/filament-comments.php index 56b519d..fcec684 100644 --- a/resources/lang/pt_BR/filament-comments.php +++ b/resources/lang/pt_BR/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Comentário deletado.', 'modal.heading' => 'Comentários', + + 'notify_users.placeholder' => 'Selecione usuários para notificar...', + 'notify_users.notification_title' => 'Novo comentário de :user', + 'notify_users.notification_action' => 'Ver registro', ]; diff --git a/resources/lang/ru/filament-comments.php b/resources/lang/ru/filament-comments.php index 45c2f66..07f45c8 100644 --- a/resources/lang/ru/filament-comments.php +++ b/resources/lang/ru/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Комментарий удален.', 'modal.heading' => 'Комментарии', + + 'notify_users.placeholder' => 'Выберите пользователей для уведомления...', + 'notify_users.notification_title' => 'Новый комментарий от :user', + 'notify_users.notification_action' => 'Просмотреть запись', ]; diff --git a/resources/lang/uk/filament-comments.php b/resources/lang/uk/filament-comments.php index e3e192c..5ee4248 100644 --- a/resources/lang/uk/filament-comments.php +++ b/resources/lang/uk/filament-comments.php @@ -10,4 +10,8 @@ 'notifications.deleted' => 'Коментар видалено.', 'modal.heading' => 'Коментарі', + + 'notify_users.placeholder' => 'Виберіть користувачів для сповіщення...', + 'notify_users.notification_title' => 'Новий коментар від :user', + 'notify_users.notification_action' => 'Переглянути запис', ]; diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index 021999d..4fcd557 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -2,10 +2,12 @@ namespace Parallax\FilamentComments\Livewire; +use Filament\Facades\Filament; use Filament\Forms; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Forms\Form; +use Filament\Notifications\Actions\Action; use Filament\Notifications\Notification; use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; @@ -31,14 +33,29 @@ public function form(Form $form): Form return $form; } + $schema = []; + + if (config('filament-comments.notify_users')) { + $users = config('filament-comments.authenticatable')::query() + ->where('id', '!=', auth()->id()) + ->pluck(config('filament-comments.user_name_attribute'), 'id'); + $schema[] = Forms\Components\Select::make('users_to_notify') + ->hiddenLabel() + ->placeholder(__('filament-comments::filament-comments.notify_users.placeholder')) + ->options($users) + ->multiple() + ->searchable() + ->preload(); + } + if (config('filament-comments.editor') === 'markdown') { - $editor = Forms\Components\MarkdownEditor::make('comment') + $schema[] = Forms\Components\MarkdownEditor::make('comment') ->hiddenLabel() ->required() ->placeholder(__('filament-comments::filament-comments.comments.placeholder')) ->toolbarButtons(config('filament-comments.toolbar_buttons')); } else { - $editor = Forms\Components\RichEditor::make('comment') + $schema[] = Forms\Components\RichEditor::make('comment') ->hiddenLabel() ->required() ->placeholder(__('filament-comments::filament-comments.comments.placeholder')) @@ -47,9 +64,7 @@ public function form(Form $form): Form } return $form - ->schema([ - $editor, - ]) + ->schema($schema) ->statePath('data'); } @@ -74,6 +89,26 @@ public function create(): void ->success() ->send(); + if (config('filament-comments.notify_users')) { + $title = __('filament-comments::filament-comments.notify_users.notification_title', [ + 'user' => auth()->user()[config('filament-comments.user_name_attribute')] + ]); + $viewAction = Action::make('view') + ->label(__('filament-comments::filament-comments.notify_users.notification_action')) + ->url(Filament::getResourceUrl($this->record, 'view')) + ->color('info') + ->close(); + Notification::make() + ->title($title) + ->body($data['comment']) + ->icon(config('filament-comments.icons.action')) + ->iconColor('info') + ->actions([ + $viewAction, + ]) + ->sendToDatabase(config('filament-comments.authenticatable')::find($data['users_to_notify'])); + } + $this->form->fill(); } From f6ed51534f670f948b8af219927a0791a8eedbf2 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Tue, 25 Feb 2025 12:11:26 +0100 Subject: [PATCH 2/9] Translate delete tooltip --- resources/lang/de/filament-comments.php | 2 ++ resources/lang/en/filament-comments.php | 2 ++ resources/lang/fa/filament-comments.php | 2 ++ resources/lang/fr/filament-comments.php | 2 ++ resources/lang/it/filament-comments.php | 2 ++ resources/lang/nl/filament-comments.php | 2 ++ resources/lang/no/filament-comments.php | 2 ++ resources/lang/pt_BR/filament-comments.php | 2 ++ resources/lang/ru/filament-comments.php | 2 ++ resources/lang/uk/filament-comments.php | 2 ++ 10 files changed, 20 insertions(+) diff --git a/resources/lang/de/filament-comments.php b/resources/lang/de/filament-comments.php index e2aa441..dc0d203 100644 --- a/resources/lang/de/filament-comments.php +++ b/resources/lang/de/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Kommentare', + 'comments.delete.tooltip' => 'Kommentar löschen', + 'notify_users.placeholder' => 'Benutzer auswählen, die benachrichtigt werden sollen...', 'notify_users.notification_title' => 'Neuer Kommentar von :user', 'notify_users.notification_action' => 'Datensatz anzeigen', diff --git a/resources/lang/en/filament-comments.php b/resources/lang/en/filament-comments.php index c2d905a..34bdd6c 100644 --- a/resources/lang/en/filament-comments.php +++ b/resources/lang/en/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Comments', + 'comments.delete.tooltip' => 'Delete comment', + 'notify_users.placeholder' => 'Select users to notify...', 'notify_users.notification_title' => 'New comment from :user', 'notify_users.notification_action' => 'View record', diff --git a/resources/lang/fa/filament-comments.php b/resources/lang/fa/filament-comments.php index 16f5438..0d185ff 100644 --- a/resources/lang/fa/filament-comments.php +++ b/resources/lang/fa/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'نظرات', + 'comments.delete.tooltip' => 'حذف نظر', + 'notify_users.placeholder' => 'کاربرانی را انتخاب کنید که مایل به اطلاع رسانی هستند...', 'notify_users.notification_title' => 'نظر جدید از :user', 'notify_users.notification_action' => 'مشاهده رکورد', diff --git a/resources/lang/fr/filament-comments.php b/resources/lang/fr/filament-comments.php index 6020a97..0d91d14 100644 --- a/resources/lang/fr/filament-comments.php +++ b/resources/lang/fr/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Commentaires', + 'comments.delete.tooltip' => 'Supprimer le commentaire', + 'notify_users.placeholder' => 'Sélectionner les utilisateurs à notifier...', 'notify_users.notification_title' => 'Nouveau commentaire de :user', 'notify_users.notification_action' => 'Voir l\'enregistrement', diff --git a/resources/lang/it/filament-comments.php b/resources/lang/it/filament-comments.php index 0b760de..e14cf47 100644 --- a/resources/lang/it/filament-comments.php +++ b/resources/lang/it/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Commenti', + 'comments.delete.tooltip' => 'Cancella commento', + 'notify_users.placeholder' => 'Seleziona utenti da notificare...', 'notify_users.notification_title' => 'Nuovo commento da :user', 'notify_users.notification_action' => 'Visualizza record', diff --git a/resources/lang/nl/filament-comments.php b/resources/lang/nl/filament-comments.php index 3ccb537..4482873 100644 --- a/resources/lang/nl/filament-comments.php +++ b/resources/lang/nl/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Reacties', + 'comments.delete.tooltip' => 'Verwijder reactie', + 'notify_users.placeholder' => 'Selecteer gebruikers om op de hoogte te stellen...', 'notify_users.notification_title' => 'Nieuwe reactie van :user', 'notify_users.notification_action' => 'Bekijk record', diff --git a/resources/lang/no/filament-comments.php b/resources/lang/no/filament-comments.php index e1241c6..47760f0 100644 --- a/resources/lang/no/filament-comments.php +++ b/resources/lang/no/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Kommentarer', + 'comments.delete.tooltip' => 'Slett kommentar', + 'notify_users.placeholder' => 'Velg brukere som skal varsles...', 'notify_users.notification_title' => 'Ny kommentar fra :user', 'notify_users.notification_action' => 'Se post', diff --git a/resources/lang/pt_BR/filament-comments.php b/resources/lang/pt_BR/filament-comments.php index fcec684..e7fd713 100644 --- a/resources/lang/pt_BR/filament-comments.php +++ b/resources/lang/pt_BR/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Comentários', + 'comments.delete.tooltip' => 'Deletar comentário', + 'notify_users.placeholder' => 'Selecione usuários para notificar...', 'notify_users.notification_title' => 'Novo comentário de :user', 'notify_users.notification_action' => 'Ver registro', diff --git a/resources/lang/ru/filament-comments.php b/resources/lang/ru/filament-comments.php index 07f45c8..d46d98e 100644 --- a/resources/lang/ru/filament-comments.php +++ b/resources/lang/ru/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Комментарии', + 'comments.delete.tooltip' => 'Удалить комментарий', + 'notify_users.placeholder' => 'Выберите пользователей для уведомления...', 'notify_users.notification_title' => 'Новый комментарий от :user', 'notify_users.notification_action' => 'Просмотреть запись', diff --git a/resources/lang/uk/filament-comments.php b/resources/lang/uk/filament-comments.php index 5ee4248..88d35de 100644 --- a/resources/lang/uk/filament-comments.php +++ b/resources/lang/uk/filament-comments.php @@ -11,6 +11,8 @@ 'modal.heading' => 'Коментарі', + 'comments.delete.tooltip' => 'Видалити коментар', + 'notify_users.placeholder' => 'Виберіть користувачів для сповіщення...', 'notify_users.notification_title' => 'Новий коментар від :user', 'notify_users.notification_action' => 'Переглянути запис', From 7ce0931769f8ab1d3875e4a469796403aaac0093 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Tue, 25 Feb 2025 12:26:33 +0100 Subject: [PATCH 3/9] security: sanitize raw HTML https://filamentphp.com/docs/3.x/forms/fields/rich-editor#security --- resources/views/comments.blade.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/views/comments.blade.php b/resources/views/comments.blade.php index ce6c2f3..26ae94b 100644 --- a/resources/views/comments.blade.php +++ b/resources/views/comments.blade.php @@ -2,7 +2,7 @@ @if (auth()->user()->can('create', \Parallax\FilamentComments\Models\FilamentComment::class))
{{ $this->form }} - + @if(config('filament-comments.editor') === 'markdown') - {{ Str::of($comment->comment)->markdown()->toHtmlString() }} + {{ Str::of($comment->comment)->markdown()->sanitizeHtml()->toHtmlString() }} @else - {{ Str::of($comment->comment)->toHtmlString() }} + {{ Str::of($comment->comment)->sanitizeHtml()->toHtmlString() }} @endif
@@ -63,7 +63,7 @@ icon="{{ config('filament-comments.icons.empty') }}" class="h-12 w-12 text-gray-400 dark:text-gray-500" /> - +
{{ __('filament-comments::filament-comments.comments.empty') }}
From 29f0d8cc327d4aeea80543ed8090ed9436c898af Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Tue, 25 Feb 2025 21:13:01 +0100 Subject: [PATCH 4/9] feat: allow editor file upload config For upload validation refer to https://livewire.laravel.com/docs/uploads#global-validation --- config/filament-comments.php | 8 ++++++++ src/Livewire/CommentsComponent.php | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/config/filament-comments.php b/config/filament-comments.php index 6283390..8373c93 100644 --- a/config/filament-comments.php +++ b/config/filament-comments.php @@ -43,6 +43,7 @@ * The rich editor toolbar buttons that are available to users. */ 'toolbar_buttons' => [ + 'attachFiles', 'blockquote', 'bold', 'bulletList', @@ -56,6 +57,13 @@ 'undo', ], + /* + * The disk on which editor uploads are stored, needs 'attachFiles' to be added to 'toolbar_buttons'. + */ + 'editor_disk' => 'public', + 'editor_directory' => 'comments', + 'editor_visibility' => 'public', + /* * Allow user to select other users to be notified via Filament database notifications. */ diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index 4fcd557..64063f8 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -53,14 +53,20 @@ public function form(Form $form): Form ->hiddenLabel() ->required() ->placeholder(__('filament-comments::filament-comments.comments.placeholder')) - ->toolbarButtons(config('filament-comments.toolbar_buttons')); + ->toolbarButtons(config('filament-comments.toolbar_buttons')) + ->fileAttachmentsDisk(config('filament-comments.editor_disk')) + ->fileAttachmentsDirectory(config('filament-comments.editor_directory')) + ->fileAttachmentsVisibility(config('filament-comments.editor_visibility')); } else { $schema[] = Forms\Components\RichEditor::make('comment') ->hiddenLabel() ->required() ->placeholder(__('filament-comments::filament-comments.comments.placeholder')) ->extraInputAttributes(['style' => 'min-height: 6rem']) - ->toolbarButtons(config('filament-comments.toolbar_buttons')); + ->toolbarButtons(config('filament-comments.toolbar_buttons')) + ->fileAttachmentsDisk(config('filament-comments.editor_disk')) + ->fileAttachmentsDirectory(config('filament-comments.editor_directory')) + ->fileAttachmentsVisibility(config('filament-comments.editor_visibility')); } return $form From 40212588a414b3fe17f4ff2638c2bffc2cea9436 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Tue, 25 Feb 2025 23:41:14 +0100 Subject: [PATCH 5/9] Apply comment_model from config --- resources/views/comments.blade.php | 2 +- src/Actions/CommentsAction.php | 1 - src/FilamentCommentsServiceProvider.php | 5 +---- src/Infolists/Components/CommentsEntry.php | 1 - src/Livewire/CommentsComponent.php | 3 +-- src/Models/Traits/HasFilamentComments.php | 1 - src/Tables/Actions/CommentsAction.php | 1 - 7 files changed, 3 insertions(+), 11 deletions(-) diff --git a/resources/views/comments.blade.php b/resources/views/comments.blade.php index 26ae94b..13646a5 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', config('filament-comments.comment_model')))
{{ $this->form }} diff --git a/src/Actions/CommentsAction.php b/src/Actions/CommentsAction.php index 5112c20..6f3bb3a 100644 --- a/src/Actions/CommentsAction.php +++ b/src/Actions/CommentsAction.php @@ -5,7 +5,6 @@ use Filament\Actions\Action; use Filament\Support\Enums\MaxWidth; use Illuminate\Contracts\View\View; -use Parallax\FilamentComments\Models\FilamentComment; class CommentsAction extends Action { diff --git a/src/FilamentCommentsServiceProvider.php b/src/FilamentCommentsServiceProvider.php index a90b6d5..1f88f80 100644 --- a/src/FilamentCommentsServiceProvider.php +++ b/src/FilamentCommentsServiceProvider.php @@ -5,15 +5,12 @@ use Filament\Support\Assets\Asset; use Filament\Support\Assets\Css; use Filament\Support\Facades\FilamentAsset; -use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Facades\Gate; use Livewire\Livewire; use Spatie\LaravelPackageTools\Commands\InstallCommand; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; use Parallax\FilamentComments\Livewire\CommentsComponent; -use Parallax\FilamentComments\Models\FilamentComment; -use Parallax\FilamentComments\Policies\FilamentCommentPolicy; class FilamentCommentsServiceProvider extends PackageServiceProvider { @@ -55,7 +52,7 @@ public function packageBooted(): void { Livewire::component('comments', CommentsComponent::class); - Gate::policy(config('filament-comments.comment_model'), config('filament-comments.model_policy', FilamentCommentPolicy::class)); + Gate::policy(config('filament-comments.comment_model'), config('filament-comments.model_policy')); FilamentAsset::register( $this->getAssets(), diff --git a/src/Infolists/Components/CommentsEntry.php b/src/Infolists/Components/CommentsEntry.php index ab4d7c4..29270b6 100644 --- a/src/Infolists/Components/CommentsEntry.php +++ b/src/Infolists/Components/CommentsEntry.php @@ -3,7 +3,6 @@ namespace Parallax\FilamentComments\Infolists\Components; use Filament\Infolists\Components\Entry; -use Parallax\FilamentComments\Models\FilamentComment; class CommentsEntry extends Entry { diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index 64063f8..f23eb3d 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -12,7 +12,6 @@ use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; use Livewire\Component; -use Parallax\FilamentComments\Models\FilamentComment; class CommentsComponent extends Component implements HasForms { @@ -120,7 +119,7 @@ public function create(): void public function delete(int $id): void { - $comment = FilamentComment::find($id); + $comment = config('filament-comments.comment_model')::find($id); if (!$comment) { return; diff --git a/src/Models/Traits/HasFilamentComments.php b/src/Models/Traits/HasFilamentComments.php index 88252af..e63c80a 100644 --- a/src/Models/Traits/HasFilamentComments.php +++ b/src/Models/Traits/HasFilamentComments.php @@ -3,7 +3,6 @@ namespace Parallax\FilamentComments\Models\Traits; use Illuminate\Database\Eloquent\Relations\HasMany; -use Parallax\FilamentComments\Models\FilamentComment; trait HasFilamentComments { diff --git a/src/Tables/Actions/CommentsAction.php b/src/Tables/Actions/CommentsAction.php index 9b60967..90d0962 100644 --- a/src/Tables/Actions/CommentsAction.php +++ b/src/Tables/Actions/CommentsAction.php @@ -6,7 +6,6 @@ use Filament\Support\Enums\MaxWidth; use Illuminate\Contracts\View\View; use Illuminate\Database\Eloquent\Model; -use Parallax\FilamentComments\Models\FilamentComment; class CommentsAction extends Action { From 94822d5d7b9dacb80cede82ac04c43e901c0f79c Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Wed, 26 Feb 2025 00:09:07 +0100 Subject: [PATCH 6/9] Use authenticatable key name instead of 'id' --- src/Livewire/CommentsComponent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index f23eb3d..c90921c 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -36,8 +36,8 @@ public function form(Form $form): Form if (config('filament-comments.notify_users')) { $users = config('filament-comments.authenticatable')::query() - ->where('id', '!=', auth()->id()) - ->pluck(config('filament-comments.user_name_attribute'), 'id'); + ->where(auth()->user()->getKeyName(), '!=', auth()->id()) + ->pluck(config('filament-comments.user_name_attribute'), auth()->user()->getKeyName()); $schema[] = Forms\Components\Select::make('users_to_notify') ->hiddenLabel() ->placeholder(__('filament-comments::filament-comments.notify_users.placeholder')) From 652369aaa4b5ee36c811eeb43d890059ede33f71 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Fri, 28 Feb 2025 21:54:12 +0100 Subject: [PATCH 7/9] Close notifications modal and auto open comments modal https://filamentphp.com/docs/3.x/panels/pages#opening-an-action-modal-when-a-page-loads --- src/Livewire/CommentsComponent.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index c90921c..2382e31 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -100,8 +100,9 @@ public function create(): void ]); $viewAction = Action::make('view') ->label(__('filament-comments::filament-comments.notify_users.notification_action')) - ->url(Filament::getResourceUrl($this->record, 'view')) ->color('info') + ->url(Filament::getResourceUrl($this->record, 'view', ['action' => 'comments'])) + ->dispatch('close-modal', ['id' => 'database-notifications']) ->close(); Notification::make() ->title($title) From 4fba092a0ab21a42060855e42bd98e2411806eb3 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Fri, 28 Feb 2025 21:59:29 +0100 Subject: [PATCH 8/9] Workaround to dispatch close-modal filamentphp/filament#15747 --- src/Livewire/CommentsComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index 2382e31..bdb6e7c 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -102,7 +102,7 @@ public function create(): void ->label(__('filament-comments::filament-comments.notify_users.notification_action')) ->color('info') ->url(Filament::getResourceUrl($this->record, 'view', ['action' => 'comments'])) - ->dispatch('close-modal', ['id' => 'database-notifications']) + ->extraAttributes(['wire:click' => '$dispatch(`close-modal`, JSON.parse`{\u0022id\u0022:\u0022database-notifications\u0022}`))']) ->close(); Notification::make() ->title($title) From 0fac43665a3d7ecf289ca197d26d37b41391ba45 Mon Sep 17 00:00:00 2001 From: Ahmed Kandil Date: Fri, 28 Feb 2025 22:24:02 +0100 Subject: [PATCH 9/9] Add missing parentheses --- src/Livewire/CommentsComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Livewire/CommentsComponent.php b/src/Livewire/CommentsComponent.php index bdb6e7c..ca98c13 100644 --- a/src/Livewire/CommentsComponent.php +++ b/src/Livewire/CommentsComponent.php @@ -102,7 +102,7 @@ public function create(): void ->label(__('filament-comments::filament-comments.notify_users.notification_action')) ->color('info') ->url(Filament::getResourceUrl($this->record, 'view', ['action' => 'comments'])) - ->extraAttributes(['wire:click' => '$dispatch(`close-modal`, JSON.parse`{\u0022id\u0022:\u0022database-notifications\u0022}`))']) + ->extraAttributes(['wire:click' => '$dispatch(`close-modal`, JSON.parse(`{\u0022id\u0022:\u0022database-notifications\u0022}`))']) ->close(); Notification::make() ->title($title)