Subscription Management
Commentions includes a subscription system that allows users to subscribe to receive notifications when new comments are added to a commentable resource.
Subscription Actions
You can add subscription actions to your Filament resources:
use Kirschbaum\Commentions\Filament\Actions\SubscriptionAction;
// In header actions
protected function getHeaderActions(): array
{
return [
SubscriptionAction::make(),
];
}
// In table actions (Filament 3)
->actions([
SubscriptionTableAction::make(),
])
// In record actions (Filament 4)
->recordActions([
SubscriptionAction::make(),
])
Subscription Sidebar
When using comments in modals, a subscription sidebar is automatically displayed showing:
- Subscribe/unsubscribe button for the current user
- List of users currently subscribed to the commentable
- Real-time updates when subscription status changes
Livewire options
When using the commentions::comments Livewire component directly, you can control the sidebar and its contents via component properties:
sidebarEnabled(bool, default: true): toggles the entire subscription sidebarshowSubscribers(bool, default:config('commentions.subscriptions.show_subscribers', true)): toggles the subscribers list within the sidebar
Examples:
For Livewire 3:
// Hide the sidebar entirely
<livewire:commentions::comments :mentionables="App\Models\User::all()" :record="$record" :sidebar-enabled="false" />
// Keep the sidebar, but hide the subscribers list (uses config default if omitted)
<livewire:commentions::comments :mentionables="App\Models\User::all()" :record="$record" :show-subscribers="false" />
For Livewire 4:
// Hide the sidebar entirely
<livewire:commentions.comments :mentionables="App\Models\User::all()" :record="$record" :sidebar-enabled="false" />
// Keep the sidebar, but hide the subscribers list (uses config default if omitted)
<livewire:commentions.comments :mentionables="App\Models\User::all()" :record="$record" :show-subscribers="false" />
Inside the component/template you can also rely on these computed properties:
canSubscribe: whether the current user can subscribeisSubscribed: whether the current user is subscribed to the current recordsubscribers: a collection of current subscribers
The component exposes a toggleSubscription() action which subscribes/unsubscribes the current user.
Disabling the Subscription Sidebar
You can disable the subscription sidebar if you don't want subscription functionality:
use Kirschbaum\Commentions\Filament\Actions\CommentsAction;
->recordActions([
CommentsAction::make()
->mentionables(User::all())
->disableSidebar()
])
Subscription Methods
The HasComments trait provides methods for managing subscriptions programmatically:
// Subscribe a user
$commentable->subscribe($user);
// Unsubscribe a user
$commentable->unsubscribe($user);
// Check if a user is subscribed
$isSubscribed = $commentable->isSubscribed($user);
// Get all subscribers
$subscribers = $commentable->getSubscribers();