Download the PHP package ansezz/laravel-gamify without Composer
On this page you can find all versions of the php package ansezz/laravel-gamify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ansezz/laravel-gamify
More information about ansezz/laravel-gamify
Files in ansezz/laravel-gamify
Package laravel-gamify
Short Description Add Gamification in laravel app with point and badges support
License MIT
Homepage https://github.com/ansezz/laravel-gamify
Informations about the package laravel-gamify
π Laravel Gamify πΉ
Laravel Gamify: Gamification System with Points & Badges support
Use ansezz/laravel-gamify
to quickly add point & badges in your Laravel app.
Installation
1 - You can install the package via composer:
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.
In Laravel 5.5 and above the service provider automatically.
3 - Now publish the migration for gamify tables:
Note: It will generate migration for points
, badges
, gamify_groups
, pointables
, badgables
tables, you will need to run composer require doctrine/dbal
in order to support dropping and adding columns.
You can publish the config file:
If 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
.
Getting Started
1. After package installation now add the Gamify trait on App\User
model or any model who acts as user in your app.
βοΈPoint π
2. Next step is to create a point.
- The point class is option because we save the point in database.
- You can create a point directly in your database without class.
- Create the point class if you need to add a check before achieve the point or if you wanna define a dynamic point value.
They will ask you if you wanna create the database badge record.
class attribute in badges table will take the class with namespace in this case:
App\Gamify\Points\PostCreated
It will create a Point class named PostCreated
under app/Gamify/Points/
folder.
in __invoke
you can add any condition to check if user achieve the point else return true
, esle we use config('gamify.point_is_archived')
by default you can change it in you config file gamify.php
.
Give point to User
Undo a given point
In some cases you would want to undo a given point.
You can also pass second argument as $event (Boolean) in function achievePoint & undoPoint ($point, $event)
, default is true
, to disable sending PointsChanged
event.
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.
Get total reputation
To get the total user points achieved you have achieved_points
attribute available..
Get points history
the package stores all the points event log so you can get the history of points via the following relation:
Get badges history
the package stores all the badges in database so you can get the history of badges via the following relation:
Event on points changed
Whenever user point changes it fires \Ansezz\Gamify\Events\PointsChanged
event which has the following payload:
This event also broadcast in configured channel name so you can listen to it from your frontend via socket to live update points.
π Achievement Badges π
Similar 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 file.
Create a Badge
To generate a badge you can run following provided command:
They will ask you if you wanna create the database badge record.
class attribute in badges table will take the class with namespace in this case:
App\Gamify\Badges\PostCreated
It will create a BadgeType class named PostCreated
under app/Gamify/Badges/
folder.
For each level you need to define a function by level name to check if the subject is achieve the badge, esle we use config('gamify.badge_is_archived')
by default you can change it in you config file gamify.php
.
Check if badge is Achieved by subject
Sync All badges
Sync One badge
Event on badge achieved
Whenever user point changes it fires \Ansezz\Gamify\Events\BadgeAchieved
event which has the following payload:
Config Gamify
Changelog
Please see CHANGELOG for more information on what has changed recently.
Testing
The package contains some integration/smoke tests, set up with Orchestra. The tests can be run via phpunit.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Anass Ez-zouaine (Author)
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-gamify with dependencies
laravel/framework Version ~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0