### Install and Configure Filament Forum Source: https://context7.com/tappnetwork/filament-forum/llms.txt Installs the Filament Forum package via Composer, publishes and runs migrations, and publishes the configuration file. This is the initial setup step for the forum package. ```bash composer require tapp/filament-forum php artisan vendor:publish --tag="filament-forum-migrations" php artisan migrate php artisan vendor:publish --tag="filament-forum-config" ``` -------------------------------- ### Install and Run Filament Forum Tests (Bash) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Provides bash commands to install the Pest testing framework, publish Filament Forum's test files into your application, and run the specific forum tests using Artisan. ```bash # Install Pest testing framework composer require pestphp/pest --dev # Publish test files to your application php artisan filament-forum:install-tests # Run forum tests php artisan test --filter=FilamentForum ``` -------------------------------- ### Create Forum with Custom Fields Test (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md An extended test case demonstrating how to create a forum with additional custom fields. This example adds a 'slug' and a 'custom_field' to the forum creation process. ```php it('can create a forum with custom fields', function () { $user = $this->userModel::factory()->create(); $this->actingAs($user); $forum = Forum::factory()->create([ 'name' => 'Test Forum', 'slug' => 'test-forum', 'custom_field' => 'custom value', // Your custom field ]); expect($forum->custom_field)->toBe('custom value'); }); ``` -------------------------------- ### Install Filament Forum Package Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Installs the Filament Forum package using Composer. This is the first step in integrating the forum functionality into your Filament application. ```bash composer require tapp/filament-forum ``` -------------------------------- ### Install Filament Forum Tests using Artisan Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md This bash command installs ready-to-use test files for the Filament Forum package into your Laravel application's `tests/Feature` directory. It requires the Pest testing framework and model factories for your User and Tenant models. ```bash php artisan filament-forum:install-tests ``` -------------------------------- ### Configure Tenancy with Team Model (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Example configuration for Filament Forum to use the `App\Models\Team` as the tenant model. This implies tests will use `Team::factory()`, look for `team_id`, and expect a `team()` relationship. ```php // config/filament-forum.php 'tenancy' => [ 'enabled' => true, 'model' => App\Models\Team::class, ], ``` -------------------------------- ### Configure Tenancy with Organization Model (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Example configuration for Filament Forum to use the `App\Models\Organization` as the tenant model. Tests will utilize `Organization::factory()`, expect a `organization_id` column, and a `organization()` relationship. ```php // config/filament-forum.php 'tenancy' => [ 'enabled' => true, 'model' => App\Models\Organization::class, ], ``` -------------------------------- ### Get Tenant Relationship and Column Names (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Illustrates how to dynamically retrieve the tenant relationship name and corresponding column name using helper methods provided by the Forum model. This ensures compatibility with different tenant model configurations. ```php // Get the tenant relationship name (e.g., 'team', 'organization', 'company') $tenantRelationship = Forum::getTenantRelationshipName(); // Get the tenant column name (e.g., 'team_id', 'organization_id', 'company_id') $tenantColumn = Forum::getTenantRelationshipName() . '_id'; ``` -------------------------------- ### Disable Tenancy Configuration (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Configuration example disabling tenancy for the Filament Forum plugin. When disabled, only basic forum tests will run, and tenancy-specific tests will be skipped. ```php // config/filament-forum.php 'tenancy' => [ 'enabled' => false, ], ``` -------------------------------- ### Test Multiple Tenant Memberships and Switching (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Demonstrates testing the ability to handle multiple tenant memberships for a user and switching between tenants using Filament's `setTenant` and `getTenant` methods. ```php it('can handle multiple tenant memberships', function () { $user = $this->userModel::factory()->create(); $tenant1 = $this->tenantModel::factory()->create(); $tenant2 = $this->tenantModel::factory()->create(); // Add user to both tenants (implement based on your membership logic) $user->teams()->attach([$tenant1->id, $tenant2->id]); $this->actingAs($user); // Test tenant switching Filament::setTenant($tenant1); expect(Filament::getTenant()->id)->toBe($tenant1->id); Filament::setTenant($tenant2); expect(Filament::getTenant()->id)->toBe($tenant2->id); }); ``` -------------------------------- ### Basic Forum Creation Test (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md A basic test case for creating a forum. It sets up a user, acts as that user, creates a forum instance using its factory, and asserts the forum's name. ```php it('can create a forum', function () { $user = $this->userModel::factory()->create(); $this->actingAs($user); $forum = Forum::factory()->create([ 'name' => 'Test Forum', ]); expect($forum->name)->toBe('Test Forum'); }); ``` -------------------------------- ### Run Migrations for Filament Forum Tests Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Executes database migrations in the testing environment to ensure tables exist. This CLI command is crucial for setting up the database schema before running tests. ```bash php artisan migrate --env=testing ``` -------------------------------- ### Read Configuration in Tests (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Demonstrates how to read plugin configuration values like user and tenant models within test files. This allows tests to dynamically use the application's configured User and Tenant models. ```php // In the test files $userModel = config('filament-forum.user.model'); $tenantModel = config('filament-forum.tenancy.model'); ``` -------------------------------- ### Define Tenant Model for Filament Forum (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Defines the `Team` model which will be used as the tenant in a multi-tenant setup. It implements `FilamentModelsContractsHasName` for displaying the tenant's name and includes a `users` relationship. ```php belongsToMany(User::class); } public function getFilamentName(): string { return $this->name; } } ``` -------------------------------- ### Run Filament Forum Tests using Artisan Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md This bash command executes the installed tests for the Filament Forum package using the Pest testing framework. It filters the tests to specifically run those related to Filament Forum functionality. ```bash php artisan test --filter=FilamentForum ``` -------------------------------- ### Configure In-Memory SQLite for Filament Forum Tests Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Sets up an in-memory SQLite database for testing by modifying the phpunit.xml configuration file. This is a common practice for fast and isolated testing environments. ```xml ``` -------------------------------- ### Configure Test Database for Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Specifies the application environment as testing and defines the test database name within the phpunit.xml configuration file. This ensures tests run against a dedicated database. ```xml ``` -------------------------------- ### Verify Filament Forum Tenancy Configuration Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Clears the configuration cache and uses Artisan Tinker to verify that tenancy is enabled in the Filament Forum configuration. This helps diagnose issues with multi-tenancy functionality. ```bash php artisan config:clear php artisan tinker >>> config('filament-forum.tenancy.enabled') ``` -------------------------------- ### Customize Mentionable Users in Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Override the `getMentionableUsers` method in your User model to define which users are available for mentions. This example shows how to only include active users. ```php // In your User model public static function getMentionableUsers() { // Only active users return static::where('is_active', true)->get(); } ``` -------------------------------- ### Test Custom Permissions for Forums (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md This test verifies that custom permissions are respected when creating forums. It simulates different user roles ('user' and 'admin') to check access control. ```php it('respects forum permissions', function () { $user = $this->userModel::factory()->create(); $admin = $this->userModel::factory()->create(['role' => 'admin']); $this->actingAs($user); $this->assertDatabaseMissing('forums', ['name' => 'Admin Forum']); $this->actingAs($admin); $forum = Forum::factory()->create(['name' => 'Admin Forum']); expect($forum)->toBeInstanceOf(Forum::class); }); ``` -------------------------------- ### Tenancy Enabled Check in Tests (PHP) Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md This test snippet shows how to conditionally skip tests if tenancy is not enabled in the application's configuration. It checks the `filament-forum.tenancy.enabled` setting. ```php beforeEach(function () { if (! config('filament-forum.tenancy.enabled')) { $this->markTestSkipped('Tenancy is not enabled'); } // ... }); ``` -------------------------------- ### Create Model Factories for Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/PUBLISH_TESTS.md Generates factories for User and Team models, which are necessary for testing. This command-line interface (CLI) command uses the Artisan tool to create the factory files. ```bash php artisan make:factory UserFactory --model=User php artisan make:factory TeamFactory --model=Team ``` -------------------------------- ### Grant Forum Admin Access in Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Override the `isForumAdmin` method in your User model to programmatically determine if a user has forum administrator privileges. This example grants admin access based on user roles. ```php // In your User model public function isForumAdmin(): bool { // Example: Grant admin access based on roles return $this->hasRole('Admin') || $this->hasRole('Forum Admin'); } ``` -------------------------------- ### Publish and Run Filament Forum Migrations Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Publishes and runs the database migrations for the Filament Forum package. This command creates the necessary tables for forums, posts, and comments in your database. Ensure tenancy is configured before running if multi-tenancy is enabled. ```bash php artisan vendor:publish --tag="filament-forum-migrations" php artisan migrate ``` -------------------------------- ### ForumPost Model: Create, Views, Comments, and Favorites Source: https://context7.com/tappnetwork/filament-forum/llms.txt Illustrates creating forum posts, recording views, retrieving view statistics, managing comments, adding comments programmatically, checking edit status, accessing relationships, and handling post favoriting/unfavoriting. Requires the ForumUser trait on the User model for favoriting. ```php 'Welcome to the Community', 'content' => '

This is the first post in our new forum!

', 'forum_id' => $forum->id, 'user_id' => auth()->id(), ]); // Record a view (automatically tracks unique views per user) $post->recordView(); // Get view statistics $viewCount = $post->views_count; $hasViewed = $post->hasBeenViewedByUser(auth()->user()); // Work with comments $comments = $post->getComments(); $commentCount = $post->comments()->count(); $uniqueCommenters = $post->getCountDistinctUsersWhoCommented(); $lastCommentTime = $post->getLastCommentTime(); // "5 minutes ago" $recentCommenters = $post->getCommentAuthors(); // Last 3 users who commented // Add a comment programmatically $comment = $post->addComment( content: '

Great post! Welcome everyone.

', author: auth()->user() ); // Check if post was edited $wasEdited = $post->hasBeenEdited(); // Access relationships $forum = $post->forum; $author = $post->user; // Favorite/unfavorite posts (requires ForumUser trait on User model) auth()->user()->favoriteForumPosts()->attach($post->id); auth()->user()->favoriteForumPosts()->detach($post->id); // Get user's favorite posts $favorites = auth()->user()->favoriteForumPosts; ``` -------------------------------- ### Forum Model: Create, Access, and Activity Source: https://context7.com/tappnetwork/filament-forum/llms.txt Demonstrates creating public and hidden forums, assigning users, querying accessible forums, checking access permissions, and retrieving forum statistics like post count, unique posters, and last activity. It also shows how to access the forum owner and its posts. ```php 'General Discussion', 'description' => 'A place for general conversations', 'owner_id' => auth()->id(), 'is_hidden' => false, ]); // Create a hidden forum (restricted access) $privateForum = Forum::create([ 'name' => 'Team Alpha Channel', 'description' => 'Private discussions for Team Alpha', 'owner_id' => auth()->id(), 'is_hidden' => true, ]); // Assign users to a hidden forum $privateForum->users()->attach([1, 2, 3]); // Query forums accessible to current user $accessibleForums = Forum::accessibleTo(auth()->user())->get(); // Check if a user can access a specific forum $canAccess = $forum->canBeAccessedBy(auth()->user()); // true/false // Get forum statistics $postCount = $forum->forumPosts()->count(); $uniquePosters = $forum->getCountDistinctUsersWhoPosted(); $lastActivity = $forum->getLastActivity(); // "2 hours ago" $recentUsers = $forum->getRecentUsers(); // Collection of last 3 users who posted // Access forum owner $owner = $forum->owner; // Get all posts in a forum $posts = $forum->posts()->latest()->get(); ``` -------------------------------- ### Configure Multi-Tenancy for Filament Forum (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Enables multi-tenancy to scope forums and posts to tenant models like teams or organizations. Configuration must be done before running migrations. When enabled, all forum content is automatically scoped to the current tenant, and database tables include tenant foreign keys. ```php [ 'enabled' => true, 'model' => \App\Models\Team::class, 'relationship_name' => 'team', 'column' => 'team_id', ], // ... other config ]; ``` -------------------------------- ### Configure Filament Forum Resources and Settings (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Provides comprehensive configuration options for Filament Forum, including frontend and admin resource classes, user model and attribute settings, multi-tenancy parameters, and URL slugs for forum and forum post resources. ```php [ 'forumResource' => \Tapp\FilamentForum\Filament\Resources\Forums\ForumResource::class, 'forumPostResource' => \Tapp\FilamentForum\Filament\Resources\ForumPosts\ForumPostResource::class, ], // Admin Filament resources 'admin-resources' => [ 'adminForumResource' => \Tapp\FilamentForum\Filament\Resources\Admin\ForumResource::class, 'adminForumPostResource' => \Tapp\FilamentForum\Filament\Resources\Admin\ForumPostResource::class, ], // User configuration 'user' => [ // The attribute used for displaying user names (can be an accessor) 'title-attribute' => 'name', // Your User model class 'model' => 'App\\Models\\User', ], // Multi-tenancy settings (configure before migrations!) 'tenancy' => [ 'enabled' => false, 'model' => null, 'relationship_name' => null, 'column' => null, ], // URL slugs for resources 'forum' => [ 'slug' => 'forums', ], 'forum-post' => [ 'slug' => 'forum-posts', ], ]; ``` -------------------------------- ### Publish Filament Forum Configuration Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Publishes the configuration file for the Filament Forum package. This allows you to customize various aspects of the forum's behavior, such as multi-tenancy settings. ```bash php artisan vendor:publish --tag="filament-forum-config" ``` -------------------------------- ### Configure Filament Panel for Tenancy Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Enables tenancy for your Filament panel by specifying the tenant model and including the ForumAdminPlugin. This ensures that forum and post data is scoped to the correct tenant. ```php use Filament\Panel; use App\Models\Team; public function panel(Panel $panel): Panel { return $panel // ... other configuration ->tenant(Team::class) ->plugins([ ForumAdminPlugin::make(), // ... other plugins ]); } ``` -------------------------------- ### Create and Manage Forum Comments (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Demonstrates how to create a new forum comment using the `addComment` method, check authorship, retrieve author details, and determine if a comment has been edited. It also shows how to extract mentioned users from the comment's HTML content. ```php addComment( content: '

Great discussion! @John what do you think?

', author: auth()->user() ); // Check authorship $isAuthor = $comment->isAuthor(auth()->user()); // Get author information $authorName = $comment->getAuthorName(); $authorAvatar = $comment->getAuthorAvatar(); // URL or generated avatar // Check if comment was edited $wasEdited = $comment->hasBeenEdited(); // Extract mentioned users from comment content $mentionedUsers = $comment->getMentioned(); // Collection of User models // Access relationships $post = $comment->forumPost; $author = $comment->author; $reactions = $comment->reactions; // Add media attachments $comment->addMedia('/path/to/image.jpg') ->toMediaCollection('attachments'); // Get media $attachments = $comment->getMedia('attachments'); ``` -------------------------------- ### Configure Filament Forum Multi-Tenancy Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Configures multi-tenancy support for the Filament Forum package by editing the `config/filament-forum.php` file. This allows forums and posts to be scoped to specific tenants. ```php 'tenancy' => [ // Enable tenancy support 'enabled' => true, // The Tenant model class (e.g., App\Models\Team::class, App\Models\Organization::class) 'model' => \App\Models\Team::class, // The tenant relationship name (optional) // Defaults to snake_case of tenant model class name // For example: Team::class -> 'team', Organization::class -> 'organization' 'relationship_name' => 'team', // The tenant column name (optional) // Defaults to snake_case of tenant model class name + '_id' // For example: Team::class -> 'team_id', Organization::class -> 'organization_id' 'column' => 'team_id', ] ``` -------------------------------- ### Configure User Model for Filament Multi-Tenancy (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Configures the `User` model to work with Filament's multi-tenancy features. It uses the `ForumUser` trait and implements `FilamentModelsContractsFilamentUser` and `FilamentModelsContractsHasTenants` to manage tenant access. ```php belongsToMany(Team::class); } public function canAccessPanel(Panel $panel): bool { return true; } public function getTenants(Panel $panel): Collection { return $this->teams; } public function canAccessTenant(Model $tenant): bool { return $this->teams()->whereKey($tenant)->exists(); } } ``` -------------------------------- ### Implement User Model Contracts for Tenancy Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Implements Filament's tenancy contracts (`FilamentUser`, `HasTenants`) on the User model. This allows users to access the panel and defines how users are associated with tenants (teams). ```php use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasTenants; use Filament\Panel; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Support\Collection; class User extends Authenticatable implements FilamentUser, HasTenants { // Define the relationship to your tenant model (eg. teams) public function teams(): BelongsToMany { return $this->belongsToMany(Team::class); } // Required by FilamentUser public function canAccessPanel(Panel $panel): bool { return true; // Customize as needed } // Required by HasTenants public function getTenants(Panel $panel): Collection { return $this->teams; } // Required by HasTenants public function canAccessTenant(Model $tenant): bool { return $this->teams()->whereKey($tenant)->exists(); } } ``` -------------------------------- ### Implement Tenant Model Contract for Display Name Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Implements Filament's `HasName` contract on the Tenant model (e.g., `Team`). This contract provides a display name for the tenant within the Filament panel. ```php use Filament\Models\Contracts\HasName; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; class Team extends Model implements HasName { // Define the inverse relationship public function users(): BelongsToMany { return $this->belongsToMany(User::class); } // Required by HasName public function getFilamentName(): string { return $this->name; } } ``` -------------------------------- ### Manage Reactions for Forum Comments (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Illustrates how to manage emoji reactions on forum comments. This includes toggling reactions for a specific user, retrieving reaction counts for all reaction types, and fetching the reactions made by the current user. ```php toggleReaction('thumbs_up', auth()->user()); $comment->toggleReaction('heart', auth()->user()); // Get reaction statistics $reactionCounts = $comment->getReactionCounts(); // Returns: ['thumbs_up' => 5, 'heart' => 3, 'laugh' => 1] // Get current user's reactions $userReactions = $comment->getUserReactions(auth()->user()); // Returns Collection: ['thumbs_up', 'heart'] ``` -------------------------------- ### Register Filament Forum Plugin in Admin Panel Provider (PHP) Source: https://context7.com/tappnetwork/filament-forum/llms.txt Registers the `ForumAdminPlugin` within the Filament admin panel configuration. This step is crucial for enabling the forum features within the admin interface and requires specifying the tenant model. ```php id('admin') ->path('admin') ->tenant(Team::class) ->plugins([ ForumAdminPlugin::make(), ]); } ``` -------------------------------- ### Handle Filament Forum Events with PHP Listeners Source: https://context7.com/tappnetwork/filament-forum/llms.txt This code demonstrates how to create PHP listener classes for various Filament Forum events. Each listener handles a specific event (e.g., UserWasMentioned, ForumCommentCreated) and performs actions like sending notifications. These listeners are designed to be registered in Laravel's EventServiceProvider. ```php mentionedUser; $comment = $event->comment; $post = $comment->forumPost; $mentionedUser->notify(new UserMentionedNotification($comment)); } } // Listener for new comments class NotifyPostAuthorOfComment implements ShouldQueue { public function handle(ForumCommentCreated $event): void { $comment = $event->comment; $post = $comment->forumPost; $postAuthor = $post->user; // Don't notify if commenting on own post if ($comment->author_id !== $postAuthor->id) { $postAuthor->notify(new NewCommentNotification($comment)); } } } // Listener for new posts class NotifyForumSubscribers implements ShouldQueue { public function handle(ForumPostCreated $event): void { $post = $event->forumPost; $forum = $post->forum; // Notify forum subscribers $forum->users->each(function ($user) use ($post) { if ($user->id !== $post->user_id) { $user->notify(new NewPostNotification($post)); } }); } } // Listener for reactions class NotifyCommentAuthorOfReaction implements ShouldQueue { public function handle(CommentWasReacted $event): void { $reactor = $event->mentionedUser; $comment = $event->comment; $reaction = $event->reaction; // Notify comment author of reaction if ($comment->author_id !== $reactor->id) { $comment->author->notify(new ReactionNotification($reaction)); } } } ``` -------------------------------- ### Publish Filament Forum Translations Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Publishes the translation files for the Filament Forum package. This allows you to customize the language strings used throughout the forum interface. ```bash php artisan vendor:publish --tag="filament-forum-translations" ``` -------------------------------- ### Configure User Model for Filament Forum Source: https://context7.com/tappnetwork/filament-forum/llms.txt Adds the ForumUser trait to your User model to integrate forum functionality. This provides relationships, methods for mentions, search, and admin access control. ```php avatar_url; } // Optional: Control which users can be @mentioned public static function getMentionableUsers() { return static::where('is_active', true)->get(); } // Optional: Grant admin access to hidden forums public function isForumAdmin(): bool { return $this->hasRole('Admin') || $this->hasRole('Forum Moderator'); } // Optional: Custom search for user selects public static function getForumSearchResults(string $search): ?array { return static::query() ->where('name', 'like', "%{$search}%") ->orWhere('email', 'like', "%{$search}%") ->limit(50) ->pluck('name', 'id') ->all(); } // Optional: Custom option label display public static function getForumOptionLabel($value): ?string { $user = static::find($value); return $user ? "{$user->name} ({$user->email})" : null; } } ``` -------------------------------- ### Register Filament Forum Frontend Plugin Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Registers the Filament Forum frontend plugin within your Filament application's user-facing panel. This makes the forum accessible to end-users. ```php use Tapp\FilamentForum\Filament\ForumPlugin; public function panel(Panel $panel): Panel { return $panel // ... other configuration ->plugins([ ForumPlugin::make(), // ... other plugins ]); } ``` -------------------------------- ### Register Filament Forum Frontend Plugin Source: https://context7.com/tappnetwork/filament-forum/llms.txt Registers the ForumPlugin within your Filament frontend panel provider. This enables the user-facing forum interface for your application. ```php id('app') ->path('app') ->plugins([ ForumPlugin::make(), ]); } } ``` -------------------------------- ### Implement User Avatar Interface in Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Implement Filament's `HasAvatar` interface in your User model to provide a URL for the user's avatar. The `getFilamentAvatarUrl` method should return the URL of the avatar. ```php use Filament\Models\Contracts\HasAvatar; class User extends Authenticatable implements HasAvatar { public function getFilamentAvatarUrl(): ?string { return $this->avatar_url; } } ``` -------------------------------- ### Customize User Search Methods in Filament Forum Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Override `getForumSearchResults` and `getForumOptionLabel` in your User model to customize how users are searched and displayed in the forum. This allows for custom search queries and formatted option labels. ```php where('name', 'like', "%{$search}%") ->orWhere('email', 'like', "%{$search}%") ->limit(50) ->pluck('name', 'id') ->all(); } /** * Custom option label display */ public static function getForumOptionLabel($value): ?string { $user = static::find($value); return $user ? "{$user->name} ({$user->email})" : null; } } ``` -------------------------------- ### Include Filament Forum TailwindCSS Styles Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Adds the necessary TailwindCSS styles for the Filament Forum frontend to your custom theme file. This ensures the forum pages are styled correctly. ```css @source '../../../../vendor/tapp/filament-forum'; ``` -------------------------------- ### Register Filament Forum Admin Plugin Source: https://context7.com/tappnetwork/filament-forum/llms.txt Registers the ForumAdminPlugin within your Filament admin panel provider. This enables the backend management interface for the forum package. ```php default() ->id('admin') ->path('admin') ->plugins([ ForumAdminPlugin::make(), ]); } } ``` -------------------------------- ### Configure User Model and Title Attribute Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Configures the Filament Forum plugin to use a specific User model and defines the attribute used for displaying the user's name in relationships. This is useful if your User model does not have a 'name' column. ```php 'user' => [ 'title-attribute' => 'name', 'model' => 'App\\Models\\User', // Your User model class ], ``` -------------------------------- ### Register Filament Forum Event Listeners in EventServiceProvider Source: https://context7.com/tappnetwork/filament-forum/llms.txt This PHP code snippet shows how to register the custom event listeners with their corresponding Filament Forum events within Laravel's EventServiceProvider. This configuration ensures that the defined listeners are executed when the specified events are dispatched. ```php [ SendUserMentionedNotification::class, ], ForumCommentCreated::class => [ NotifyPostAuthorOfComment::class, ], ForumPostCreated::class => [ NotifyForumSubscribers::class, ], CommentWasReacted::class => [ NotifyCommentAuthorOfReaction::class, ], ]; } ``` -------------------------------- ### Disable Tenancy in Filament Forum Configuration Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Disables the tenancy feature for the Filament Forum plugin by setting 'enabled' to false in the configuration file. This reverts forum and post data to not be tenant-scoped. ```php 'tenancy' => [ 'enabled' => false, 'model' => null, ], ``` -------------------------------- ### Register Filament Forum Admin Plugin Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Registers the Filament Forum admin plugin within your Filament application's backend. This enables the forum management resources in the admin panel. ```php use Tapp\FilamentForum\Filament\ForumAdminPlugin; public function panel(Panel $panel): Panel { return $panel // ... other configuration ->plugins([ ForumAdminPlugin::make(), // ... other plugins ]); } ``` -------------------------------- ### Handle UserMentioned Event in Laravel Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md This snippet demonstrates how to listen for the `UserWasMentioned` event in Laravel and send a notification to the mentioned user. It utilizes Laravel's event and notification system. The event contains the mentioned user and the comment instance. ```php namespace App\Listeners; use App\Notifications\UserMentionedNotification; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Illuminate\Queue\InteractsWithQueue; use Tapp\FilamentForum\Events\UserWasMentioned; class SendUserMentionedNotification implements ShouldQueue { use InteractsWithQueue; public function handle(UserWasMentioned $event): void { $mentionedUser = $event->mentionedUser; $comment = $event->comment; // Send notification to the mentioned user $mentionedUser->notify(new UserMentionedNotification($comment)); // Or dispatch a custom notification Notification::make() ->title('You were mentioned in a comment') ->body("You were mentioned by {$comment->author->name}") ->sendToDatabase($mentionedUser); } } ``` ```php use Tapp\FilamentForum\Events\UserWasMentioned; use App\Listeners\SendUserMentionedNotification; protected $listen = [ UserWasMentioned::class => [ SendUserMentionedNotification::class, ], ]; ``` -------------------------------- ### Create Custom User Mention Notification in Laravel Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md This PHP code defines a custom notification class `UserMentionedNotification` for Laravel. It specifies how to send notifications via database and email when a user is mentioned in a forum comment. The notification includes details about the comment and its author. ```php namespace App\Notifications; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use Tapp\FilamentForum\Models\ForumComment; class UserMentionedNotification extends Notification { public function __construct( public ForumComment $comment ) {} public function via($notifiable) { return ['database', 'mail']; } public function toDatabase($notifiable) { return [ 'title' => 'You were mentioned', 'body' => "You were mentioned in a comment by {$this->comment->author->name}", 'comment_id' => $this->comment->id, 'forum_post_id' => $this->comment->forumPost->id, ]; } public function toMail($notifiable) { return (new MailMessage) ->subject('You were mentioned in a forum comment') ->line("You were mentioned in a comment by {$this->comment->author->name}") ->action('View Comment', route('forum.posts.show', $this->comment->forumPost)); } } ``` -------------------------------- ### Integrate ForumUser Trait into User Model Source: https://github.com/tappnetwork/filament-forum/blob/main/README.md Adds the ForumUser trait to your application's User model. This trait provides necessary methods and relationships for user interactions within the forum, such as managing forums and favorite posts. ```php use Tapp\FilamentForum\Traits\ForumUser; class User extends Authenticatable { // ... use ForumUser; // ... } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.