Likeable) that can be integrated into any Eloquent model without tight coupling. This aligns well with Laravel’s modular design and follows the Single Responsibility Principle (SRP) for like/favorite functionality.likeables) for tracking likes, which is a standard pattern but may require schema adjustments if the project already has a custom like system.Likeable trait in Laravel 10).id column, UUIDs, or custom fields)? Does the package support this?composer require rtconner/laravel-likeable
php artisan vendor:publish --provider="Conner\Likeable\LikeableServiceProvider"
php artisan migrate
Article, Post):
class Article extends Model {
use \Conner\Likeable\Likeable;
// Customize if needed:
// public $likeableType = 'articles';
// public $likeableId = 'uuid';
}
@if($article->liked())
<button onclick="unlike()">Unlike</button>
@else
<button onclick="like()">Like</button>
@endif
<span>{{ $article->likeCount }}</span>
public $likeableUserId = 'user_id'; // Custom column name
tenant_id.deleted_at.Article) as a proof of concept.Comment, Product).user_id, likeable_id, likeable_type).likeCount in Redis for frequently accessed models.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Database connection issues | Likes not recorded/unrecorded | Retry logic, queue jobs, notifications. |
| Race conditions (duplicate likes) | Inflated like counts | Database-level uniqueness constraints. |
| Pivot table corruption | Broken like tracking | Regular database backups, migrations. |
| Laravel version incompatibility | Package breaks | Test in staging, fork if needed. |
| High traffic spikes | Slow responses | Caching, read replicas, queue background jobs. |
How can I help you explore Laravel packages today?