{"id":19540945,"url":"https://github.com/qirolab/laravel-reactions","last_synced_at":"2025-05-15T15:06:28.268Z","repository":{"id":43175299,"uuid":"140428012","full_name":"qirolab/laravel-reactions","owner":"qirolab","description":"Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion, etc) on Eloquent models.","archived":false,"fork":false,"pushed_at":"2025-02-26T09:14:55.000Z","size":113,"stargazers_count":183,"open_issues_count":0,"forks_count":23,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T22:01:11.541Z","etag":null,"topics":["dislike","eloquent","emotion","favorite","kudos","laravel","like","love","rate","rating","reaction","star","unlike"],"latest_commit_sha":null,"homepage":"https://qirolab.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qirolab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"custom":"https://www.buymeacoffee.com/qirolab"}},"created_at":"2018-07-10T12:23:07.000Z","updated_at":"2025-03-11T04:47:37.000Z","dependencies_parsed_at":"2023-01-28T13:40:30.594Z","dependency_job_id":"2d944ab7-96a2-4293-b2aa-e1b421fb1161","html_url":"https://github.com/qirolab/laravel-reactions","commit_stats":{"total_commits":83,"total_committers":6,"mean_commits":"13.833333333333334","dds":0.2650602409638554,"last_synced_commit":"8858c8b0dd1559c5142b779a9d115973d7995523"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qirolab%2Flaravel-reactions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qirolab%2Flaravel-reactions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qirolab%2Flaravel-reactions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qirolab%2Flaravel-reactions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qirolab","download_url":"https://codeload.github.com/qirolab/laravel-reactions/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254364270,"owners_count":22058878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dislike","eloquent","emotion","favorite","kudos","laravel","like","love","rate","rating","reaction","star","unlike"],"created_at":"2024-11-11T03:08:04.407Z","updated_at":"2025-05-15T15:06:28.247Z","avatar_url":"https://github.com/qirolab.png","language":"PHP","funding_links":["https://www.buymeacoffee.com/qirolab"],"categories":[],"sub_categories":[],"readme":"# Add Reactions (like, dislike, etc.) to Eloquent Model\n\n\u003cimg src=\"https://i.imgur.com/RQApy96.png\" /\u003e\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/qirolab/laravel-reactions.svg?style=flat-square)](https://packagist.org/packages/qirolab/laravel-reactions)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/qirolab/laravel-reactions/Tests?label=Tests)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3ATests+branch%3Amaster)\n[![Styling](https://github.com/qirolab/laravel-reactions/workflows/Check%20\u0026%20fix%20styling/badge.svg)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3A%22Check+%26+fix+styling%22)\n[![Psalm](https://github.com/qirolab/laravel-reactions/workflows/Psalm/badge.svg)](https://github.com/qirolab/laravel-reactions/actions?query=workflow%3APsalm)\n[![Total Downloads](https://img.shields.io/packagist/dt/qirolab/laravel-reactions.svg?style=flat-square)](https://packagist.org/packages/qirolab/laravel-reactions)\n\nLaravel reactions package for implementing reactions (eg: like, dislike, love,\nemotion etc) on Eloquent models.\n\n## Video Tutorial\n\n**[ ▶️ Laravel Reactions Tutorial](https://www.youtube.com/watch?v=VMaXBYYDfg8)**\n\n## Installation\n\nDownload package into the project using Composer.\n\n```bash\ncomposer require qirolab/laravel-reactions\n```\n\n### Registering package\n\u003e Laravel 5.5 (or higher) uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.\n\nFor Laravel 5.4 or earlier releases version include the service provider within `app/config/app.php`:\n\n```php\n'providers' =\u003e [\n    Qirolab\\Laravel\\Reactions\\ReactionsServiceProvider::class,\n],\n```\n\n### Database Migration\nIf you want to make changes in migrations, publish them to your application first.\n\n```bash\nphp artisan vendor:publish --provider=\"Qirolab\\Laravel\\Reactions\\ReactionsServiceProvider\" --tag=migrations\n```\n\nRun database migrations.\n```bash\nphp artisan migrate\n```\n\n### Config File\nYou can optionally publish the config file with:\n```bash\nphp artisan vendor:publish --provider=\"Qirolab\\Laravel\\Reactions\\ReactionsServiceProvider\" --tag=\"config\"\n```\n\n## Usage\n\n### Prepare Reacts (User) Model\nUse `Qirolab\\Laravel\\Reactions\\Contracts\\ReactsInterface` contract in model which will perform react behavior on reactable model and implement it and use `Qirolab\\Laravel\\Reactions\\Traits\\Reacts` trait.\n\n```php\nuse Qirolab\\Laravel\\Reactions\\Traits\\Reacts;\nuse Qirolab\\Laravel\\Reactions\\Contracts\\ReactsInterface;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable implements ReactsInterface\n{\n    use Reacts;\n}\n```\n\n### Prepare Reactable Model\n\nUse `Qirolab\\Laravel\\Reactions\\Contracts\\ReactableInterface` contract in model which will get reaction behavior and implement it and use `Qirolab\\Laravel\\Reactions\\Traits\\Reactable` trait.\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Qirolab\\Laravel\\Reactions\\Traits\\Reactable;\nuse Qirolab\\Laravel\\Reactions\\Contracts\\ReactableInterface;\n\nclass Article extends Model implements ReactableInterface\n{\n    use Reactable;\n}\n```\n\n## Available Methods\n\n### Reaction\n```php\n$user-\u003ereactTo($article, 'like');\n\n$article-\u003ereact('like'); // current login user\n$article-\u003ereact('like', $user);\n```\n\n### Remove Reaction\nRemoving reaction of user from reactable model.\n```php\n$user-\u003eremoveReactionFrom($article);\n\n$article-\u003eremoveReaction(); // current login user\n$article-\u003eremoveReaction($user);\n```\n\n### Toggle Reaction\nThe toggle reaction method will add a reaction to the model if the user has not reacted. If a user has already reacted, then it will replace the previous reaction with a new reaction. For example, if the user has reacted 'like' on the model. Now on toggles reaction to 'dislike' then it will remove the 'like' and stores the 'dislike' reaction.\n\nIf a user has reacted `like` then on toggle reaction with `like`. It will remove the reaction.\n\n```php\n$user-\u003etoggleReactionOn($article, 'like');\n\n$article-\u003etoggleReaction('like'); // current login user\n$article-\u003etoggleReaction('like', $user);\n```\n\n### Boolean check if user reacted on model\n\n```php\n$user-\u003eisReactedOn($article));\n\n$article-\u003eis_reacted; // current login user\n$article-\u003eisReactBy(); // current login user\n$article-\u003eisReactBy($user);\n```\n\n### Reaction summary on model\n```php\n$article-\u003ereactionSummary();\n$article-\u003ereaction_summary;\n\n// example\n$article-\u003ereaction_summary-\u003etoArray();\n// output\n/*\n[\n    \"like\" =\u003e 5,\n    \"dislike\" =\u003e 2,\n    \"clap\" =\u003e 4,\n    \"hooray\" =\u003e 1\n]\n*/\n```\n\n### Get collection of users who reacted on model\n```php\n$article-\u003ereactionsBy();\n```\n\n### Scopes\nFind all articles reacted by user.\n```php\nArticle::whereReactedBy()-\u003eget(); // current login user\n\nArticle::whereReactedBy($user)-\u003eget();\nArticle::whereReactedBy($user-\u003eid)-\u003eget();\n```\n\n### Reaction on Model\n```php\n// It will return the Reaction object that is reacted by given user.\n$article-\u003ereacted($user);\n$article-\u003ereacted(); // current login user\n$article-\u003ereacted; // current login user\n\n$user-\u003ereactedOn($article);\n```\n\n### Events\n\nOn each reaction added `\\Qirolab\\Laravel\\Reactions\\Events\\OnReaction` event is fired.\n\nOn each reaction removed `\\Qirolab\\Laravel\\Reactions\\Events\\OnDeleteReaction` event is fired.\n\n### Testing\n\nRun the tests with:\n\n```bash\nvendor/bin/phpunit\n```\n\n[![Spec Coder](https://i.imgur.com/lqkt7a3.png)](https://qirolab.com/spec-coder)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqirolab%2Flaravel-reactions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqirolab%2Flaravel-reactions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqirolab%2Flaravel-reactions/lists"}