- How do I install hypefactors/laravel-follow in a Laravel app?
- Run composer require hypefactors/laravel-follow, then publish the package config and migration with the vendor:publish command and run php artisan migrate. After that, add the CanFollow trait to the model that performs the action (typically User) and the Followable trait to every model that can be followed. The integration surface is small, so a working spike usually takes one to two engineer-days including authorization and API exposure.
- Does laravel-follow support Laravel 11, Laravel 12, and PHP 8.3+?
- The package's last release was July 2023, and there is no evidence of CI coverage for Laravel 11/12 or PHP 8.3+, so composer constraints alone are not proof of support. Validate the traits against your target Laravel major in a short spike before committing. If you hit incompatibilities, the BSD-3-Clause license makes vendoring or forking the two traits a realistic fallback.
- Can models follow things other than users, like tags or teams?
- Yes. Both sides of the relationship are polymorphic (follower and followable), so the same pivot table supports User-to-User, User-to-Tag, User-to-Team, or any heterogeneous follow graph. This makes it suitable for social follows, subscriptions to entities, or watch semantics without a bespoke schema. It is a relationship store only, so feeds, ranking, and notifications stay in your application.
- How do I check whether a model is already following another model?
- Use the relationship helpers exposed by the traits, such as isFollowing() to test a specific target and the follow, unfollow, and toggle methods to change state. Because these are standard Eloquent calls, they compose cleanly with policies, gates, and API resources. Keep authorization for who may follow whom in your own policy layer rather than in the package.
- How do I avoid N+1 queries when listing followers and following?
- The followers() and followings() methods return normal Eloquent relations, so eager load them with with() and use withCount() for follower totals instead of looping per model. Paginate large listings and index the pivot table on follower and followable columns. Denormalized counts are not provided out of the box, so cache or maintain counters yourself if you need high-read performance.
- Does laravel-follow prevent duplicate follows?
- Duplicate prevention depends on the pivot table schema, so inspect the published migration and confirm there is a composite unique index across follower and followable columns. If it is missing, add it before you ship, because retrofitting a unique index on a large table is the expensive part. Also be aware that toggle operations involve a check-then-insert pattern, so guard against races with the unique constraint or a transaction.
- Are UUID or ULID primary keys supported on both sides of the polymorphic relation?
- Support depends on the column types used in the shipped migration; standard morphs columns assume integer keys, so you may need uuidMorphs or ulidMorphs instead. Verify that the follower and followable key columns match the key type and length of your target tables. On MySQL, also check utf8mb4 index length limits and collation consistency between the pivot and the related tables.
- Does the package fire follow or unfollow events for notifications and auditing?
- Events are not documented in the package overview, so verify in the source before you rely on them. If none are dispatched, wrap follow and unfollow calls in your own service or model observer that fires application events for notifications, audit logs, and cache invalidation. Keeping that logic outside the package also makes it easier to fork or replace the traits later.
- What happens to pivot rows when a followed model or follower is deleted?
- Polymorphic pivot tables typically cannot use database foreign key cascades on both sides, so deleting a model can leave orphaned follow rows. Plan for cleanup by detaching relationships in a model observer or running a scheduled pruning job. Test deletion paths explicitly, since stale rows will skew follower counts and relationship checks.
- When should I use laravel-follow instead of building my own follow table or using another package?
- Use it when you want a quick, dependency-free polymorphic follow store with a tiny trait-based API and a permissive BSD-3-Clause license. Avoid it if you need feed fan-out, ranked activity streams, mute or block semantics, or guaranteed support for the newest Laravel and PHP versions, since those are product-owned concerns and the package has a low maintenance signal at roughly 49 stars. In those cases, hand-rolling a pivot table or forking the traits is often the safer long-term choice.