- How do I install ryangjchandler/laravel-comments in a Laravel application?
- Install it with Composer using composer require ryangjchandler/laravel-comments. Package auto-discovery registers the service provider, so no manual provider entry is needed. Publish the config and migration with the package's vendor:publish tags, run php artisan migrate, then add the traits to your models. The whole path from install to a working create-and-render flow is typically under a day.
- How do I make an existing Eloquent model commentable?
- Add the HasComments trait to the model that should receive comments, such as a Ticket, Document, or Product. Add the Commenter trait to your User model so it can author comments. Once both traits are in place, relationships like $ticket->comments() and $user->comments are available.
- Does laravel-comments support threaded or nested replies?
- Yes. The package supports nested replies on top of its polymorphic comment storage, so you can build threaded discussions without adding another dependency. Rendering the thread depth is your responsibility, since the package gives you the data layer and helpers rather than a full UI. Plan for recursion limits and query counts when you display deep threads.
- Which Laravel and PHP versions does this package support?
- Check the require block in the package's composer.json on Packagist for the exact Illuminate and PHP constraints before committing. Because it is a small single-maintainer package, verify the resolved dependency matrix against your app with composer why-not laravel/framework ^X. Do not assume support for the newest Laravel major until you have confirmed it in your own lockfile.
- Does the package include Livewire components or a ready-made UI?
- Treat it as a persistence-first package: it ships a Comment model, HasComments and Commenter traits, a publishable migration, config, and model events. Any Livewire, Blade, Inertia, or API layer on top is yours to build unless the repository's resources/ tree proves otherwise for your resolved version. Verify that directly in the repo before you estimate front-end effort.
- How are comments stored and how does polymorphic association work?
- Comments are stored in a single table with commentable_type and commentable_id columns, giving you a classic Laravel morphTo relationship. The commentable_type column stores fully qualified class names unless you alias them at install time, so retrofitting morph aliases later can break historical rows. Decide on morph-map aliases before you write production data.
- Can I swap or extend the Comment model?
- Yes, the package supports configurable model swapping through its publishable config file, so you can point it at a subclass with extra behaviour. Be careful with config caching, since a cached config can silently mask a model swap between environments. Clear and rebuild the config cache as part of your deploy pipeline.
- What happens to comments when the parent model is deleted?
- The package does not add cascade deletes for polymorphic relations, so deleting a commented model can leave orphan comment rows behind. Handle this in your own model events, observers, or a scheduled cleanup that prunes comments whose commentable record no longer exists. This is one of the few production concerns you must own explicitly.
- How do I query comments with their authors?
- Use the relationship and eager load the author, for example $ticket->comments()->with('user')->latest()->paginate(). Eager loading avoids the N+1 problem when rendering a thread, and pagination keeps long discussions manageable. For nested replies you will likely need additional queries or a recursive relationship strategy.
- Can I create comments from queued jobs, console commands, or tests?
- The package relies on the authenticated user in the ordinary request flow, so auth()->user() returning null is a real concern in jobs, commands, and some test contexts. Resolve the commenter explicitly and pass it into the create call rather than depending on the auth guard. Also note that rate limiting, mention parsing, notification fan-out, moderation queues, soft deletes, and rich-text sanitization are not provided and remain your product and engineering work.