{"id":13828408,"url":"https://github.com/qcod/laravel-gamify","last_synced_at":"2026-01-26T13:11:42.367Z","repository":{"id":43038774,"uuid":"159589281","full_name":"qcod/laravel-gamify","owner":"qcod","description":"Gamify your Laravel app with Reputation Points \u0026 Achievements Badges support","archived":false,"fork":false,"pushed_at":"2025-05-15T03:54:43.000Z","size":41,"stargazers_count":674,"open_issues_count":26,"forks_count":72,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-10-20T02:43:53.780Z","etag":null,"topics":["achievements","badges","gamification","laravel","reputation"],"latest_commit_sha":null,"homepage":null,"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/qcod.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-29T01:29:39.000Z","updated_at":"2025-10-10T06:13:32.000Z","dependencies_parsed_at":"2024-01-20T18:06:39.368Z","dependency_job_id":"c807c02e-429c-46e9-b137-6c945221aabb","html_url":"https://github.com/qcod/laravel-gamify","commit_stats":{"total_commits":21,"total_committers":5,"mean_commits":4.2,"dds":"0.19047619047619047","last_synced_commit":"ffbdeee2c134f4958915d04a66c6a4fc9706e722"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/qcod/laravel-gamify","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcod%2Flaravel-gamify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcod%2Flaravel-gamify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcod%2Flaravel-gamify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcod%2Flaravel-gamify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qcod","download_url":"https://codeload.github.com/qcod/laravel-gamify/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qcod%2Flaravel-gamify/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28779021,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T11:46:04.308Z","status":"ssl_error","status_checked_at":"2026-01-26T11:46:02.664Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["achievements","badges","gamification","laravel","reputation"],"created_at":"2024-08-04T09:02:45.206Z","updated_at":"2026-01-26T13:11:42.348Z","avatar_url":"https://github.com/qcod.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"## Laravel Gamify  🕹 🏆\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/qcod/laravel-gamify.svg)](https://packagist.org/packages/qcod/laravel-gamify)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/qcod/laravel-gamify/master.svg)](https://travis-ci.org/qcod/laravel-gamify)\n[![Total Downloads](https://img.shields.io/packagist/dt/qcod/laravel-gamify.svg)](https://packagist.org/packages/qcod/laravel-gamify)\n\nUse `qcod/laravel-gamify` to quickly add reputation point \u0026amp; badges in your Laravel app.\n\n### Installation\n\n**1** - You can install the package via composer:\n\n```bash\n$ composer require qcod/laravel-gamify\n```\n\n**2** - If you are installing on Laravel 5.4 or lower you will be needed to manually register Service Provider by adding it in `config/app.php` providers array.\n\n```php\n'providers' =\u003e [\n    //...\n    QCod\\Gamify\\GamifyServiceProvider::class\n]\n```\n\nIn Laravel 5.5 and above the service provider automatically.\n\n**3** - Now publish the migration for gamify tables:\n\n```\nphp artisan vendor:publish --provider=\"QCod\\Gamify\\GamifyServiceProvider\" --tag=\"migrations\"\n```\n\n*Note:* It will generate migration for `reputations`, `badges` and `user_badges` tables along with add reputation field migration for `users` table to store the points, you will need to run `composer require doctrine/dbal` in order to support dropping and adding columns.\n\n```\nphp artisan migrate\n```\n\nYou can publish the config file:\n```\nphp artisan vendor:publish --provider=\"QCod\\Gamify\\GamifyServiceProvider\" --tag=\"config\"\n```\n\nIf your payee (model who will be getting the points) model is `App\\User` then you don't have to change anything in `config/gamify.php`.\n\n### Getting Started\n\n**1.** After package installation now add the **Gamify** trait on `App\\User` model or any model who acts as **user** in your app.\n\n```php\nuse QCod\\Gamify\\Gamify;\nuse Illuminate\\Notifications\\Notifiable;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;\n\nclass User extends Authenticatable\n{\n    use Notifiable, Gamify;\n```\n\n## ⭐️ 👑 Reputation Point\n\n**2.** Next step is to create a point.\n\n```bash\nphp artisan gamify:point PostCreated\n```\n\nIt will create a PointType class named `PostCreated` under `app/Gamify/Points/` folder.\n\n```php\n\u003c?php\n\nnamespace App\\Gamify\\Points;\n\nuse QCod\\Gamify\\PointType;\n\nclass PostCreated extends PointType\n{\n    /**\n     * Number of points\n     *\n     * @var int\n     */\n    public $points = 20;\n\n    /**\n     * Point constructor\n     *\n     * @param $subject\n     */\n    public function __construct($subject)\n    {\n        $this-\u003esubject = $subject;\n    }\n\n    /**\n     * User who will be receive points\n     *\n     * @return mixed\n     */\n    public function payee()\n    {\n        return $this-\u003egetSubject()-\u003euser;\n    }\n}\n```\n\n### Give point to User\n\nNow in your Controller where a Post is created you can give points like this:\n\n```php\n$user = $request-\u003euser();\n$post = $user-\u003eposts()-\u003ecreate($request-\u003eonly(['title', 'body']));\n\n// you can use helper function\ngivePoint(new PostCreated($post));\n\n// or via HasReputation trait method\n$user-\u003egivePoint(new PostCreated($post));\n```\n\n### Undo a given point\n\nIn some cases you would want to undo a given point, for example, a user deletes his post.\n\n```php\n// via helper function\nundoPoint(new PostCreated($post));\n$post-\u003edelete();\n\n// or via HasReputation trait method\n$user-\u003eundoPoint(new PostCreated($post));\n$post-\u003edelete();\n```\n\nYou can also pass second argument as $user in helper function `givePoint(new PostCreated($post), $user)`, default is auth()-\u003euser().\n\n**Pro Tip 👌** You could also hook into the Eloquent model event and give point on `created` event. Similarly, `deleted` event can be used to undo the point.\n\n### Get total reputation\n\nTo get the total user reputation you have `$user-\u003egetPoints($formatted = false)` method available. Optioally you can pass `$formatted = true` to get reputation as 1K+, 2K+ etc.\n\n```php\n// get integer point\n$user-\u003egetPoints(); // 20\n\n// formatted result\n$user-\u003egetPoints(true); // if point is more than 1000 1K+\n```\n\n### Get reputation history\n\nSince package stores all the reputation event log so you can get the history of reputation via the following relation:\n\n```php\nforeach($user-\u003ereputations as $reputation) {\n    // name of the point type \n    $reputation-\u003ename\n    \n    // payee user\n    $reputation-\u003epayee\n    \n    // how many points\n    $reputation-\u003epoint\n    \n    // model on which point was given \n    $reputation-\u003esubject\n}\n``` \n\nIf you want to get all the points given on a `subject` model. You should define a `morphMany` relations. For example on post model.\n\n```php\n    /**\n     * Get all the post's reputation.\n     */\n    public function reputations()\n    {\n        return $this-\u003emorphMany('QCod\\Gamify\\Reputation', 'subject');\n    }\n```\n\nNow you can get all the reputation given on a `Post` using `$post-\u003ereputations`.\n\n### Configure a Point Type\n\n#### Point payee\nIn most of the case your subject model which you pass into point `new PostCreated($post)` will be related to the User via some relation.\n\n```php\nclass PostCreated extends PointType\n{\n    public $points = 20;\n    \n    protected $payee = 'user';\n    \n    // dont need this, payee property will return subject realtion \n    // public function payee()\n    // {\n    //    return $this-\u003egetSubject()-\u003euser;\n    // }\n}\n```\n\n#### Dynamic point\n\nIf a point is calculated based on some logic you should add `getPoints()` method to do the calculation and always return an integer.\n\n```php\nclass PostCreated extends PointType\n{\n    protected $payee = 'user';\n    \n    public function getPoints()\n    {\n        return $this-\u003egetSubject()-\u003euser-\u003egetPoint() * 10;\n    }\n}\n```\n\n#### Point qualifier\n\nThis is an optional method which returns boolean if its true then this point will be given else it will be ignored. \nIt's will be helpful if you want to determine the qualification for point dynamically.\n\n#### Prevent duplicate reputation\n\nBy default, you can give points multiple times for same model subject. But you can prevent it by adding the following property to the class:\n\n```php\nclass PostCreated extends PointType\n{\n    // prevent duplicate point\n    public $allowDuplicates = false;\n\n    protected $payee = 'user';\n}\n```\n\n#### Event on reputation changed\n\nWhenever user point changes it fires `\\QCod\\Gamify\\Events\\ReputationChanged` event which has the following payload:\n\n```php\nclass ReputationChanged implements ShouldBroadcast {\n    \n    ...\n    public function __construct(Model $user, int $point, bool $increment)\n    {\n        $this-\u003euser = $user;\n        $this-\u003epoint = $point;\n        $this-\u003eincrement = $increment;\n    }\n}\n```\n\nThis event also broadcast in configured channel name so you can listen to it from your frontend via socket to live update reputation points.\n\n## 🏆 🏅 Achievement Badges\n\nSimilar to Point type you have badges. They can be given to users based on rank or any other criteria. You should define badge level in `config/gamify.php`.\n\n```php\n// All the levels for badge\n'badge_levels' =\u003e [\n    'beginner' =\u003e 1,\n    'intermediate' =\u003e 2,\n    'advanced' =\u003e 3,\n],\n\n// Default level\n'badge_default_level' =\u003e 1\n```\n\nBadge levels are stored as `tinyint` so keep the value as an integer value. It will be faster to do the sorting when needed. \n\n### Create a Badge\n\nTo generate a badge you can run following provided command:\n\n```bash\nphp artisan gamify:badge FirstContribution\n```\n\nIt will create a BadgeType class named `FirstContribution` under `app/Gamify/Badges/` folder.\n\n```php\n\u003c?php\n\nnamespace App\\Gamify\\Badges;\n\nuse QCod\\Gamify\\BadgeType;\n\nclass FirstContribution extends BadgeType\n{\n    /**\n     * Description for badge\n     *\n     * @var string\n     */\n    protected $description = '';\n\n    /**\n     * Check is user qualifies for badge\n     *\n     * @param $user\n     * @return bool\n     */\n    public function qualifier($user)\n    {\n        return $user-\u003egetPoints() \u003e= 1000;\n    }\n}\n```\n\nAs you can see this badge has a `$description` field and a `qualifier($user)` method. \nGamify package will listen for any change in reputation point and it will run the user against all the available badges and assign all the badges user is qualified.\n\n#### Change badge name\n\nBy default, badge name will be a pretty version on the badge class name. In the above case it will be `First Contribution`. \nYou can change it by adding a `$name` property in class or you can override `getName()` method if you want to name it dynamically.\n\n#### Change badge icon\n\nSimilar to name you can change it by `$icon` property or by `getIcon()` method. When you define icon on the class you need to specify full path with extension. \n`config/gamify.php` folder `badge_icon_folder` and `badge_icon_extension` won't be used.\n\n#### Change badge level\n\nYou have same `$level` property or by `getLevel()` method to change it.\nIts like category of badges, all badges are defined in `config/gamify.php` as `badge_levels`. If none is specified then `badge_default_level` will be used from config.\n\n**Warning ⚠️** Don't forget to clear the cache whenever you make any changes add or remove badges by running `php artisan cache:forget gamify.badges.all`. ⚠️ \n\n#### Get badges of user\nYou can get a users badges by calling `$user-\u003ebadges` which will return collection of badges for a user.\n\n### Use without Badge\n\nIf your app doesn't need **Badges** you should just use `HasReputations` trait instead of `Gamify`.  \n\n### Use without reputation history\n\nIf you dont need to maintain the history of all the point user has rewarded and you just want to increment and decrement reputation, you should use following method:\n\n```php\n// to add point\n$user-\u003eaddPoint($point = 1);\n\n// to reduce point\n$user-\u003ereducePoint($point = 1);\n\n// to reset point back to zero\n$user-\u003eresetPoint();\n```\n\nYou dont need to generate point class for this.  \n\n### Config Gamify\n\n```php\n\u003c?php\n\nreturn [\n    // Model which will be having points, generally it will be User\n    'payee_model' =\u003e '\\App\\User',\n\n    // Reputation model\n    'reputation_model' =\u003e '\\QCod\\Gamify\\Reputation',\n\n    // Allow duplicate reputation points\n    'allow_reputation_duplicate' =\u003e true,\n\n    // Broadcast on private channel\n    'broadcast_on_private_channel' =\u003e true,\n\n    // Channel name prefix, user id will be suffixed\n    'channel_name' =\u003e 'user.reputation.',\n\n    // Badge model\n    'badge_model' =\u003e '\\QCod\\Gamify\\Badge',\n\n    // Where all badges icon stored\n    'badge_icon_folder' =\u003e 'images/badges/',\n\n    // Extention of badge icons\n    'badge_icon_extension' =\u003e '.svg',\n\n    // All the levels for badge\n    'badge_levels' =\u003e [\n        'beginner' =\u003e 1,\n        'intermediate' =\u003e 2,\n        'advanced' =\u003e 3,\n    ],\n\n    // Default level\n    'badge_default_level' =\u003e 1\n];\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n### Testing\n\nThe package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.\n\n```bash\n$ composer test\n```\n\n### Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email saquibweb@gmail.com instead of using the issue tracker.\n\n### Credits\n\n- [Mohd Saqueib Ansari](https://github.com/saqueib) (Author)\n\n### About QCode.in\n\nQCode.in (https://www.qcode.in) is a blog by [Saqueib](https://github.com/saqueib) which covers All about Full Stack Web Development.\n\n### License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqcod%2Flaravel-gamify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqcod%2Flaravel-gamify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqcod%2Flaravel-gamify/lists"}