x-laravel/followable
A Laravel package that adds follow and unfollow behavior to your models. Attach polymorphic follower relationships, check whether a model is followed, and query followers or followings with a simple, reusable trait.
This release is a cohesive Laravel social-graph primitive rather than a narrow “follow button” helper. It provides polymorphic follow relationships, optional approval workflows, mutual-follow queries, cleanup/pruning, and domain events. For a TPM, the main value is that it standardizes a common product capability — follows, follow requests, and mutual connections — behind contracts, traits, configuration, and events, reducing bespoke social-graph code in each Laravel service.
Architecture fit is strong for Laravel applications already using Eloquent models and event-driven patterns. The package supports both sides of the relationship through CanFollow/Follower and HasFollowers/Followable, including one model using both. That fits typical user-to-user follows as well as heterogeneous follows such as user-to-team, user-to-topic, or user-to-content. Approval support via RequiresFollowApproval is useful for private accounts, gated communities, or moderated entities. Mutual-follow support and withFollowedBy() improve list-rendering efficiency, which is a meaningful product and performance consideration.
Integration feasibility is good but not turnkey. It will require publishing/installing migrations, configuring the follow model/table/connection, applying traits and contracts to relevant models, and deciding whether approval is required per model. The events are dispatched after commit, which is the right default for reliability, but consumers must design listeners for idempotency and failure handling. The pruning feature via model:prune is valuable, but production adoption needs a clear owner for scheduling and monitoring.
Technical risk is moderate. Polymorphic relationships are powerful but increase schema and query complexity. Cleanup on model/follower deletion is helpful, but the team should verify behavior with soft deletes, cascading deletes, and existing data-retention policies. The package’s self-follow prevention and single-follow constraint are good defaults, but race conditions and duplicate attempts should be tested under load. Approval workflows introduce state transitions that must align with product rules and notification expectations. The configurable connection/table/model is flexible but can create operational fragmentation if multiple services configure it differently.
Key questions:
Stack fit is best for Laravel services using Eloquent and a relational database. The package should slot into an existing Laravel application with minimal architectural change: add the Composer dependency, publish configuration and migrations as needed, apply the appropriate contracts/traits to follower and followable models, and wire domain events into existing notification, feed, or analytics pipelines. It is less suitable if the product needs a separate graph database, complex relationship metadata beyond follows, or non-Laravel services without an integration layer.
The migration path depends on whether we are adding new follow functionality or replacing existing bespoke follow tables. For a greenfield capability, sequence as: install and configure the package; run migrations in a non-production environment; apply traits/contracts to a pilot model such as User; validate follow, unfollow, request, accept, reject, and mutual-follow behavior; add event listeners; enable pruning in staging; then roll out model by model. For an existing follow system, sequence as: map existing data to the package schema; build a backfill or dual-write plan; validate counts, mutual states, and approval states; run read comparisons; then cut over reads and writes with a rollback path.
Compatibility considerations include the Laravel/PHP version matrix, database driver support, migration naming conflicts, and whether existing models already use traits or contracts with overlapping method names. Polymorphic type columns must be stable if models are renamed or moved. If multiple databases or connections are used, the configurable connection is helpful, but cross-database queries and reporting need explicit design. Event listeners should be compatible with after-commit dispatch and should not assume immediate consistency.
Recommended sequencing:
Maintenance burden is likely low to moderate. The package owns the core schema and relationship logic, but the application team still owns configuration, model integration, event listeners, approval UX, and production data quality. Because the package is at v1.0.0, we should expect normal early-lifecycle maintenance: pinning a version, reviewing changelogs, and testing upgrades before rollout. Supportability improves if we document which models use which contracts, where approval is required, and which events drive downstream systems.
Scaling risk is centered on the follows table. Follow relationships can grow quickly and become a high-write, high-read table. The package’s scopes for mutual follows and list-state checks are helpful, but production readiness depends on proper composite indexes, query review, and pagination. Pruning of left-behind follows is a strong operational feature, but it must be scheduled, monitored, and tuned with an appropriate frequency and chunk size. Large backfills or pruning runs should be throttled to avoid database pressure.
Failure modes to plan for include orphaned follows if cleanup does not cover every deletion path, duplicate or conflicting follow attempts under concurrency, approval-state drift between the package and application notifications, and event-listener failures after commit. The package dispatches events after commit, which reduces the chance of emitting events for rolled-back transactions, but it does not remove the need for idempotent consumers and retry handling. If pruning is misconfigured or too aggressive, valid relationships could be affected, so dry runs and monitoring are important.
Ramp-up effort is modest for a Laravel team. Engineers need to understand the contracts/traits, polymorphic relationship conventions, approval state transitions, event semantics, and pruning configuration. Product and support teams need clear definitions for follow requests, accepted/rejected states, mutual follows, and removal behavior. A short pilot with one model, documented configuration, and observable event flows should be enough to build confidence before broader rollout.
How can I help you explore Laravel packages today?