Download the PHP package miracuthbert/laravel-royalty without Composer
On this page you can find all versions of the php package miracuthbert/laravel-royalty. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download miracuthbert/laravel-royalty
More information about miracuthbert/laravel-royalty
Files in miracuthbert/laravel-royalty
Package laravel-royalty
Short Description A user points package for Laravel that can be used to give rewards, loyalty or experience points with real time support
License MIT
Informations about the package laravel-royalty
Laravel Royalty
A user points package for Laravel that can be used to give rewards, loyalty or experience points with real time support.
How does it work?
Simply every point has an action file which when called will resolve the model for a given point.
The action file is used to assign points to a user.
The reason we use action (files) is:
- It makes it easy to track points.
- It's easier to switch out points eg. you want to bump up the points a user gets on completing a lesson from
50
to100
, you just create a new action and you replace the old one.
Installation
Use composer to install the package:
Setup
The package takes advantage of Laravel Auto-Discovery, so it doesn't require you to manually add the ServiceProvider.
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
You must then publish the config
and migrations
file.
Using the Setup command
You can do all the necessary setup using the royalty:setup
in your command console
Update the keys in "config/royalty.php" before migrating your database You can set the model to be used for points.
If you want to reset either config
or migrations
use the commands below in your console
Publish Config
Setup the user
model
key in config to indicate which User model to use
Publish Migrations
Before migrating the database make sure you setup the user
model
key in config
Publish Vue Components
A simple Vue component is included to display a user's points in real-time anytime they are given points. See Real-time section under usage for more.
The package does not tie you to use a specific front-end framework to listen to the fired event, so feel free to experiment
Usage
Setting the User model
First, setup the user model
key in the config.
Then add CollectsPoints
trait in the respective model.
Creating Points
Let's take an example of a user completing a Lesson in a course, we can create a CompletedLesson
.
Using Console Command
You can use the command:
This will create an action file under the Royalty\Actions
folder in the app
directory
or a corresponding one as specified in the config/royalty.php
file.
It will include:
key
method with the unique key which will be used to identify created from the slug of theAction
name.
You can also use these options along with the command:
--key
to override the key generated from class name.--name
to create the point in the database (use along with thepoints
option).--points
the points for the given action.--description
the description of the point.
If you just created the point file only you need to create a record with reference to the action in the database.
See Adding Points in the Database section on adding a point in the database.
Creating Manually
To create a point manually you need to create an action
file and also a record
referencing the action in the database.
Creating the Action File
To create a point action file, you need to create a class that extends Miracuthbert\Royalty\Actions\ActionAbstract
.
Adding Points in the Database
You can also create bulk points using, for example a seeder:
Giving Points
To give points, just call the givePoints
method on an instance of a user.
Getting User's Points
To get user points, just call the points
method on an instance of a user chaining one of the following methods:
number
: The raw points valuenumber
: For a formatted number value, i.e1,000
,1,000,000
shorthand
: For a formatted string value, i.e1k
,10.5k
,1m
Real-time
Whenever a user is given points a PointsGiven
event is fired.
Broadcast Channel
It broadcasts to the users
(private) channel as set in the channel
key of broadcast
in config/royalty.php
.
The channel should exist in
channels
file under routes or your respective user channel
An example of the channel route:
Listening to the Event
You can then listen to it using the points-given
or the set value of the name
key under broadcast
in config/royalty.php
.
Example using Laravel Echo with Vue.js:
Vue Component
There is a Vue component included with the package. Use command below to publish it:
The published component will be placed in your resources/js/components
directory. Once the components have been published, you should register them in your resources/js/app.js
file:
After registering the component, make sure to run npm run dev
to recompile your assets. Once you have recompiled your assets, you may drop the components into one of your application's templates to get started:
Console Commands
There are three commands within the package:
royalty:setup
: Used to setup the package filesroyalty:action
: Used to create an action file and pointroyalty:actions
: Used to list points and their related actions
Security Vulnerabilities
If you discover a security vulnerability, please send an e-mail to Cuthbert Mirambo via [email protected]. All security vulnerabilities will be promptly addressed.
Credits
License
The project is open-sourced software licensed under the MIT license.
All versions of laravel-royalty with dependencies
illuminate/console Version ^7.0|^8.0|^9.0|^10.0
illuminate/database Version ^7.0|^8.0|^9.0|^10.0
illuminate/events Version ^7.0|^8.0|^9.0|^10.0
illuminate/http Version ^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0
kalnoy/nestedset Version >=5.0