- How do I install lakm/laravel-comments in a Laravel application?
- Install the package with composer require lakm/laravel-comments, then publish the config and migrations using php artisan vendor:publish for the Lakm\Commenter\CommenterServiceProvider. After publishing, run php artisan migrate to create the comments and replies tables. From there you can render the x-comments Blade component in any view; the full walkthrough lives in the GitBook documentation.
- Which Laravel and PHP versions does laravel-comments support?
- The package requires PHP 8.1 or higher, which matches the baseline for modern Laravel releases, and the README badges list support for Laravel 11, 12 and 13. Earlier integration notes reference Laravel 10 and 11, so confirm the exact constraint in composer.json on Packagist for the version you plan to install. It has no heavy external dependencies such as required queue workers or cron jobs by default.
- How do I add comments to a model like a Post using the x-comments component?
- Pass the Eloquent model you want to attach comments to as the :model prop of the Blade component, for example x-comments :model="$post". The component renders the comment list and submission form using the package's theme, so no extra JavaScript build step is required for a standard Blade setup. You can also use the @comment and @replies Blade directives if you prefer composing the markup yourself.
- Does Laravel Commenter support threaded or nested replies?
- Yes. Comments and replies are modelled separately through the package's Eloquent models and migrations, so replies can be nested under a parent comment. Replies are rendered with the @replies directive or the components shipped with the theme, and there are dedicated API endpoints for replies as well. Events such as ReplyAdded are fired so you can hook in notifications or analytics.
- How do I customize routes, middleware and validation rules in Commenter?
- Publish the package config file (config/commenter.php) and override the route prefixes, middleware stack and validation rules there instead of editing vendor code. Keeping customizations in config avoids merge conflicts when you update the package. UI changes are handled through the theming system rather than by modifying core package logic.
- Can I use lakm/laravel-comments as a headless API for a Vue or React SPA?
- Yes. The package ships RESTful endpoints such as /api/comments and /api/replies, so a Blade frontend, an SPA or a mobile app can all talk to the same backend. Because it relies on Laravel's built-in authentication (Auth::user()), you may need to adjust middleware or add token-based auth such as Sanctum if your SPA is not using session cookies. The config file lets you change middleware without forking the package.
- How do I moderate comments, and is there an admin panel?
- There is a separate admin panel package, laravel-comments-admin-panel, that gives you a UI for reviewing and moderating comments without building your own tooling. If you already have an internal dashboard, you can instead query the Comment and Reply models directly and wrap moderation actions in your own controllers. Check whether the admin panel's moderation features cover your workflow, or whether you need custom flags such as reactions or voting.
- Which databases does lakm/laravel-comments work with?
- The package is database agnostic and supports MySQL, PostgreSQL and SQLite out of the box, so there is no vendor lock-in. SQLite support makes it convenient for local development and CI pipelines. Migrations run on your application's default connection, so they coexist with your existing schema as long as you review published migrations before running them.
- How do I test comment functionality with Pest or PHPUnit?
- The package is compatible with Laravel's standard testing tools, Pest and PHPUnit, and its own test suite runs on GitHub Actions. In your application tests, use RefreshDatabase so the comment and reply tables are recreated for each run, and use Event::fake() when you want to assert that CommentCreated or ReplyAdded is dispatched without triggering listeners. Cover your own moderation rules and nested reply behaviour, since those are the areas most likely to change as the package evolves.
- Does Laravel Commenter support real-time or live comments with WebSockets?
- Not natively. Comments are persisted and rendered through standard HTTP requests and the REST API, so live updates require adding broadcasting yourself on top of the CommentCreated and ReplyAdded events. That event-driven design makes it straightforward to broadcast new comments over Pusher or Laravel Reverb if real-time behaviour is a requirement. For high-traffic pages, also consider pagination, lazy loading and a cache such as Redis for heavy comment loads.