- How do I add comments to an Eloquent model with spatie/laravel-comments?
- Install the package with Composer, publish its migrations and config, then attach the HasComments trait or implement the Commentable contract on the model that should receive comments. The package supplies the schema, Comment model, policies, notifications, and Blade components, so you can start creating comments against posts, products, or other Eloquent records with minimal setup. Full setup details are on the Spatie documentation site.
- Which Laravel and PHP versions does spatie/laravel-comments support?
- The changelog shows support for Laravel 10, Laravel 11, and Laravel 12 on PHP 8.x, with deprecation fixes for PHP 8.4 landing promptly. Because the dependency chain includes laravel-markdown, CommonMark, and symfony/html-sanitizer, you should confirm the exact Composer constraints against your application's Laravel major before upgrading. The package is maintained for currently supported Laravel versions rather than legacy releases.
- Does spatie/laravel-comments support guest commenters or only authenticated users?
- It includes an optional commentator abstraction that can represent registered users or guest commenters, and the commentator name field is configurable. That means you can decide whether comments are tied strictly to your User model or allowed from guests and service accounts. If you use morph maps, pin them so commentator and commentable types remain stable in storage.
- Can I customize the Comment model or use my own model with spatie/laravel-comments?
- Yes. The package exposes configurable model keys and lets you swap in custom models through configuration, which is useful when you need extra fields or domain-specific behavior. You can keep the package's migrations and relationships while extending the model layer. Review the config file after publishing to see which models and name fields are configurable.
- Does spatie/laravel-comments include a frontend UI or only backend models?
- It ships Blade components and views, but the UI layer assumes frontend conventions such as Tailwind-era markup and Font Awesome, with a config toggle for Font Awesome autodownload. If those conventions do not match your design system, you can consume only the models, events, and policies and build your own frontend. UI composition, moderation workflow, and abuse handling are intentionally left to the product team.
- How are comments rendered and sanitized in spatie/laravel-comments?
- Comments are authored as markdown and rendered through laravel-markdown and CommonMark, with HTML sanitization handled by symfony/html-sanitizer. The package has shipped security-relevant fixes, including an XSS fix in 1.0.7 and sanitizer configuration changes in 1.1.5, which shows the maintainer responds to reports. You should still verify sanitizer configuration against your own content policy.
- Does spatie/laravel-comments handle notifications, replies, mentions, and subscriptions?
- Yes. The documented feature surface includes reply notifications, mentions, a subscription model, and Laravel-native notification plumbing. This lets you notify participants without building a separate event bus or comment microservice. You remain responsible for deciding which events trigger notifications and how users manage their subscription preferences.
- Is spatie/laravel-comments production-ready despite its low adoption?
- The package is maintained, with Laravel 11, Laravel 12, and PHP 8.4 fixes landing promptly and security issues being addressed. However, it has roughly 32 stars and 0 dependents, so ecosystem validation is near zero and your usage pattern may expose untested edge cases. Treat it as a domain primitive with a small blast radius and make sure an internal owner can patch or wrap it if needed.
- What are alternatives to spatie/laravel-comments for Laravel applications?
- The main alternative is building your own polymorphic comments table with Eloquent relationships, policies, notifications, and sanitization, which gives full control over moderation, spam scoring, edit history, and retention. You can also evaluate other Laravel comment packages, but compare their maintenance cadence, security history, UI assumptions, and notification support. spatie/laravel-comments fits teams that want an Eloquent-native threaded discussion primitive without a separate comment service.
- How do I test spatie/laravel-comments or run its test suite?
- The package includes a test suite you can run with composer test after installing dependencies. For your own application, add integration tests around the Commentable model, guest versus authenticated commentators, notification dispatch, markdown rendering, and sanitizer output. Testing these paths is especially important because the package has limited downstream adoption and your edge cases may not be covered upstream.