Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Forum Laravel Package

courtyard/forum

Courtyard Forum is the core package of an event-driven forum platform for developers. Built to be stable, scalable, and extensible, it provides a clean API to build custom communities, with optional Symfony2 integration via ForumBundle.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to First Use Case

  1. Installation:

    composer require courtyard/forum
    

    Note: Due to Symfony2 dependencies, ensure your composer.json includes:

    "require": {
        "symfony/event-dispatcher": "^2.0",
        "symfony/security": "^2.0"
    }
    
  2. Basic Laravel Integration: Create a ForumServiceProvider in app/Providers/:

    namespace App\Providers;
    
    use Illuminate\Support\ServiceProvider;
    use Courtyard\Forum\ForumBundle;
    
    class ForumServiceProvider extends ServiceProvider
    {
        public function register()
        {
            // Override Symfony's EventDispatcher with Laravel's
            $this->app->singleton('event_dispatcher', function ($app) {
                return $app['events'];
            });
    
            // Bind Courtyard services (adjust based on package structure)
            $this->app->bind('courtyard.forum.manager', function ($app) {
                return new \Courtyard\Forum\Manager\ThreadManager(
                    $app['event_dispatcher'],
                    $app['courtyard.forum.repository.thread']
                );
            });
        }
    }
    
  3. First Use Case: Create a Thread Register the provider in config/app.php and create a controller:

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use Courtyard\Forum\Entity\Thread;
    
    class ThreadController extends Controller
    {
        public function store(Request $request)
        {
            $thread = new Thread();
            $thread->setTitle($request->title);
            $thread->setContent($request->content);
            $thread->setAuthor($request->user()); // Assuming Laravel auth
    
            // Use the manager (adjust based on actual package methods)
            $manager = app('courtyard.forum.manager');
            $manager->create($thread);
    
            return redirect()->route('threads.show', $thread->getId());
        }
    }
    
  4. Verify Events: Listen for the thread.created event in EventServiceProvider:

    protected $listen = [
        'thread.created' => [
            'App\Listeners\SendThreadCreatedNotification',
        ],
    ];
    

Where to Look First

  • Package Structure: Explore src/Courtyard/Forum/ for:
    • Entity/ (Thread, Post, User models)
    • Manager/ (ThreadManager, PostManager)
    • Event/ (thread.created, post.updated, etc.)
  • Symfony Bundle: Check ForumBundle.php for service configurations and dependencies.
  • Tests: If available, review tests/ for usage patterns (though likely Symfony-focused).

Implementation Patterns

Usage Patterns

  1. Event-Driven Workflows:

    • Pattern: Subscribe to Courtyard events to trigger Laravel logic.
      // Example: Listen for post upvotes
      event(new PostUpvoted($post));
      
    • Laravel Integration:
      // In EventServiceProvider
      protected $listen = [
          'post.upvoted' => [
              'App\Listeners\UpdateUserReputation',
          ],
      ];
      
  2. Repository Pattern:

    • Pattern: Use Courtyard’s repositories to interact with entities.
      $threadRepo = app('courtyard.forum.repository.thread');
      $threads = $threadRepo->findBy(['tag' => 'laravel']);
      
    • Laravel Adaptation: Replace with Eloquent or a custom repository layer:
      class ThreadRepository extends \Illuminate\Database\Eloquent\Model
      {
          protected $table = 'forum_threads';
          // ...
      }
      
  3. Service Layer:

    • Pattern: Use managers to orchestrate complex operations.
      $threadManager = app('courtyard.forum.manager');
      $thread = $threadManager->create($threadEntity);
      
    • Laravel Services: Wrap Courtyard services in Laravel’s container:
      $this->app->bind('courtyard.forum.manager', function ($app) {
          return new \App\Services\ForumManager(
              $app['event_dispatcher'],
              new \App\Repositories\ThreadRepository
          );
      });
      
  4. Entity Mapping:

    • Pattern: Map Courtyard entities to Laravel models.
      class Thread extends \Illuminate\Database\Eloquent\Model
      {
          protected $fillable = ['title', 'content', 'author_id'];
      
          public static function fromCourtyardEntity(\Courtyard\Forum\Entity\Thread $entity)
          {
              return self::create([
                  'title' => $entity->getTitle(),
                  'content' => $entity->getContent(),
                  'author_id' => $entity->getAuthor()->getId(),
              ]);
          }
      }
      

Workflows

  1. Thread Creation Workflow:

    • Steps:
      1. User submits a form (title, content).
      2. Create a Thread entity (Courtyard or Laravel model).
      3. Dispatch thread.created event.
      4. Trigger notifications, analytics, or moderation checks via listeners.
    • Code:
      $thread = new \App\Models\Thread([
          'title' => $request->title,
          'content' => $request->content,
          'author_id' => auth()->id(),
      ]);
      $thread->save();
      event(new \Courtyard\Forum\Event\ThreadCreated($thread));
      
  2. Moderation Workflow:

    • Pattern: Use Courtyard’s role system + Laravel policies.
      // Check if user is a moderator
      if (auth()->user()->can('moderate')) {
          $post->setStatus('hidden');
          $postManager = app('courtyard.forum.manager.post');
          $postManager->update($post);
      }
      
  3. Real-Time Updates:

    • Pattern: Combine Courtyard events with Laravel Echo/Pusher.
      // In a listener for post.created
      broadcast(new PostCreated($post))->toOthers();
      

Integration Tips

  1. Authentication:

    • Replace Symfony’s Security with Laravel’s Auth:
      $user = auth()->user(); // Instead of $security->getUser()
      
  2. Database:

    • Use Laravel Migrations to adapt Courtyard’s schema:
      Schema::create('forum_threads', function (Blueprint $table) {
          $table->id();
          $table->string('title');
          $table->text('content');
          $table->foreignId('author_id')->constrained('users');
          $table->timestamps();
      });
      
  3. Testing:

    • Write Laravel-specific tests using Tests\TestCase:
      public function test_thread_creation()
      {
          $response = $this->post('/threads', [
              'title' => 'Test Thread',
              'content' => 'Hello world',
          ]);
          $response->assertRedirect();
          $this->assertDatabaseHas('forum_threads', ['title' => 'Test Thread']);
      }
      
  4. Frontend:

    • Use Livewire for reactive components:
      public class ThreadComponent extends Component
      {
          public $thread;
      
          public function mount($id)
          {
              $this->thread = \App\Models\Thread::findOrFail($id);
          }
      
          public function render()
          {
              return view('livewire.thread');
          }
      }
      

Gotchas and Tips

Pitfalls

  1. Symfony Dependencies:

    • Issue: Courtyard relies on Symfony components (e.g., HttpFoundation, Security).
    • Fix: Override or replace them in Laravel’s container:
      $this->app->bind('request', function () {
          return Request::capture();
      });
      
  2. Event Dispatcher Mismatch:

    • Issue: Symfony’s EventDispatcher differs from Laravel’s Dispatcher.
    • Fix: Create a wrapper:
      class LaravelEventDispatcher implements \Symfony\Component\EventDispatcher\EventDispatcherInterface
      {
          protected $dispatcher;
      
          public function __construct(\Illuminate\Events\Dispatcher $dispatcher)
          {
              $this->dispatcher = $dispatcher;
          }
      
          public function dispatch($event, $eventName = null)
          {
              $this->dispatcher->dispatch($event);
          }
      }
      
  3. Entity vs. Model Confusion:

    • Issue: Courtyard uses Doctrine entities; Laravel uses Eloquent models.
    • Fix: Decide early whether to:
      • Use Courtyard entities with a custom ORM layer.
      • Convert entities to Eloquent models (recommended for Laravel).
  4. Archived Status:

    • Issue: No active maintenance or bug fixes.
    • Fix:
      • Fork the repository immediately.
      • Monitor for upstream changes and cherry-pick updates.
  5. Missing Laravel Utilities:

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed