Download the PHP package turahe/laravel-likeable without Composer
On this page you can find all versions of the php package turahe/laravel-likeable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download turahe/laravel-likeable
More information about turahe/laravel-likeable
Files in turahe/laravel-likeable
Package laravel-likeable
Short Description Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.
License MIT
Homepage https://github.com/turahe/laravel-likeable
Informations about the package laravel-likeable
Introduction
Laravel Likeable simplifies management of Eloquent model's likes & dislikes. Make any model likeable
& dislikeable
in a minute!
Contents
- Features
- Installation
- Usage
- Prepare likeable model
- Available methods
- Scopes
- Events
- Console commands
- Extending
- Change log
- Contributing
- Testing
- Continuous Integration
- Release Process
- Security
- Contributors
- Alternatives
- License
- About Turahe
Features
- ✅ Designed to work with Laravel Eloquent models
- ✅ Using contracts to keep high customization capabilities
- ✅ Using traits to get functionality out of the box
- ✅ Most part of the logic is handled by the
LikeableService
- ✅ Has Artisan command
likeable:recount {model?} {type?}
to re-fetch likes counters - ✅ Likeable model can have Likes and Dislikes
- ✅ Likes and Dislikes for one model are mutually exclusive
- ✅ Get Likeable models ordered by likes count
- ✅ Events for
like
,unlike
,dislike
,undislike
methods - ✅ Comprehensive test coverage (79 tests, 0 failures)
- ✅ Following PHP Standard Recommendations:
- ✅ Fully tested with PHPUnit
- ✅ Continuous Integration with GitHub Actions
- ✅ Code style checks with PHP CS Fixer
- ✅ Static analysis with Larastan
- ✅ Automated release workflows with conventional commits
- ✅ Semantic versioning and changelog generation
Installation
First, pull in the package through Composer.
If you are using Laravel 5.5+ you can skip the register package part.
Register package on Laravel 5.4 and lower
Include the service provider within app/config/app.php
.
Perform Database Migration
At last, you need to publish and run database migrations.
Usage
Prepare likeable model
Use Likeable
contract in model which will get likes behavior and implement it or just use Likeable
trait.
Available methods
Likes
Like model
Remove like mark from model
Toggle like mark of model
Get model likes count
Get model likes counter
Get likes relation
Get iterable Illuminate\Database\Eloquent\Collection
of existing model likes
Boolean check if user liked model
Checks in eager loaded relations likes
& likesAndDislikes
first.
Get collection of users who liked model
Delete all likes for model
Dislikes
Dislike model
Remove dislike mark from model
Toggle dislike mark of model
Get model dislikes count
Get model dislikes counter
Get dislikes relation
Get iterable Illuminate\Database\Eloquent\Collection
of existing model dislikes
Boolean check if user disliked model
Checks in eager loaded relations dislikes
& likesAndDislikes
first.
Get collection of users who disliked model
Delete all dislikes for model
Likes and Dislikes
Get difference between likes and dislikes
Get likes and dislikes relation
Get iterable Illuminate\Database\Eloquent\Collection
of existing model likes and dislikes
Scopes
Find all articles liked by user
Find all articles disliked by user
Fetch Likeable models by likes count
Uses desc
as default order direction.
Fetch Likeable models by dislikes count
Uses desc
as default order direction.
Events
On each like added \Turahe\Likeable\Events\ModelWasLiked
event is fired.
On each like removed \Turahe\Likeable\Events\ModelWasUnliked
event is fired.
On each dislike added \Turahe\Likeable\Events\ModelWasDisliked
event is fired.
On each dislike removed \Turahe\Likeable\Events\ModelWasUndisliked
event is fired.
Console commands
Recount likes and dislikes of all model types
Recount likes and dislikes of concrete model type (using morph map alias)
Recount likes and dislikes of concrete model type (using fully qualified class name)
Recount only likes of all model types
Recount only likes of concrete model type (using morph map alias)
Recount only likes of concrete model type (using fully qualified class name)
Recount only dislikes of all model types
Recount only dislikes of concrete model type (using morph map alias)
Recount only dislikes of concrete model type (using fully qualified class name)
Extending
You can override core classes of package with your own implementations:
Models\Like
Models\LikeCounter
Services\LikeableService
Note: Don't forget that all custom models must implement original models interfaces.
To make it you should use container binding interfaces to implementations in your application service providers.
Use model class own implementation
Use service class own implementation
After that your CustomLike
and CustomService
classes will be instantiable with helper method app()
.
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Testing
This package includes comprehensive test coverage with 79 tests covering all functionality:
- Common Use Tests - Basic like/unlike functionality
- Counter Tests - Like/dislike counter management
- Dislike Tests - Dislike-specific functionality
- Enum Tests - LikeType enum functionality
- Event Tests - Event dispatching
- Exception Tests - Custom exception handling
- Service Tests - Service layer functionality
- Toggle Tests - Like/dislike toggle operations
- Console Command Tests - Artisan command functionality
Running Tests
You can run the tests with:
Or use the composer script:
Test Coverage
Run tests with coverage:
This will generate HTML coverage reports in the coverage-html
directory.
Continuous Integration
This package uses GitHub Actions for continuous integration. The CI pipeline includes:
Test Matrix
- PHP Versions: 8.3, 8.4
- Laravel Versions: 11.x, 12.x
- Test Coverage: Generated for PHP 8.3+ + Laravel 11/12.x
CI Jobs
- Tests: Runs the full test suite across all PHP/Laravel combinations with code coverage
- Static Analysis: Code style checking with PHP CS Fixer and Larastan across all PHP/Laravel combinations
- Lint: PHP syntax validation
- Coverage: Detailed code coverage reporting with HTML reports
Local Development
You can run the same checks locally:
Code Coverage
Code coverage reports are generated and uploaded to Codecov.
Release Process
This package uses automated release workflows for version management and deployment.
Automated Release Workflows
Version Bump Workflow
- Trigger: Pushes to
main
branch with conventional commits - Actions:
- Runs tests, static analysis, and linting
- Updates
CHANGELOG.md
with new entries - Creates release preparation PRs for new features
- Follows Conventional Commits format
Release Workflow
- Trigger: Pushing tags with
v*
pattern (e.g.,v1.2.3
) - Actions:
- Validates code quality (tests, analysis, linting)
- Generates changelog from git history
- Creates GitHub release with assets
- Uploads
composer.json
,CHANGELOG.md
, andREADME.md
as release assets
Creating a Release
- Prepare Changes: Ensure all changes follow conventional commit format
-
Create Tag: Create and push a new version tag
- Automated Process: The release workflow will automatically:
- Run all quality checks
- Generate release notes
- Create GitHub release
- Upload release assets
Conventional Commits
This project follows the Conventional Commits specification:
feat:
- New features (triggers release preparation)fix:
- Bug fixesdocs:
- Documentation changesstyle:
- Code style changesrefactor:
- Code refactoringperf:
- Performance improvementstest:
- Test additions or changesbuild:
- Build system changesci:
- CI/CD changeschore:
- Maintenance tasks
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Contributors
- Nur Wachid - Initial work
Alternatives
- spatie/laravel-likes - A simple package to add likes to Eloquent models
- rtconner/laravel-likeable - Likeable trait for Laravel Eloquent models
License
The MIT License (MIT). Please see License File for more information.
About Turahe
Turahe is a software development company focused on creating high-quality Laravel packages and applications. Visit us at turahe.id.
All versions of laravel-likeable with dependencies
illuminate/database Version ^11.0 || ^12.0
illuminate/support Version ^11.0 || ^12.0