follows, blocks) with optimized queries for common social patterns (e.g., followers(), following() scopes). May require indexing for large-scale deployments.FollowingStarted, Blocked), enabling integration with Laravel’s ecosystem (e.g., broadcasting, queues).hasMany, belongsToMany). Requires minimal boilerplate for setup (e.g., use Befriended\Traits\Followable;).User follows Post or Comment), reducing rigid coupling.followers(), following(), blocked()) for filtering collections, but may need customization for complex business logic.rennokki) could impact long-term support.following()->posts() may require eager loading.follows, blocks) scale with millions of relationships? Are there recommendations for indexing?followed() events).User follows Post) to test integration.followers(), following()) and validate query performance.followedAt timestamps).illuminate/database, illuminate/support.HasRelationships).follows and blocks pivot tables. Example:
Schema::create('follows', function (Blueprint $table) {
$table->id();
$table->foreignId('follower_id')->constrained()->cascadeOnDelete();
$table->foreignId('followed_id')->constrained()->cascadeOnDelete();
$table->string('followed_type');
$table->timestamps();
});
composer require rennokki/befriended.Followable trait to models (e.g., User, Post).follow(), unfollow(), block() methods to controllers.CREATE INDEX follows_followed_idx ON follows(followed_id, followed_type);
$user->following()->with('posts')->get();
followers()/following() scopes.FollowingStarted, Blocked) simplify logging/auditing.spatie/laravel-followables) or commercial SDKs (e.g., Firebase Auth for social features).follower_count in a column.followers() queries.following() collections for users:
Cache::remember("user-{$user->id}-following", now()->addHours(1), function () {
return $user->following()->get();
});
follow()) scale well.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database connection loss | Broken follow/block operations | Retry logic + queue failed jobs. |
| Pivot table corruption | Inconsistent |
How can I help you explore Laravel packages today?