qcod / laravel-gamify Goto Github PK
View Code? Open in Web Editor NEWGamify your Laravel app with Reputation Points & Achievements Badges support
License: MIT License
Gamify your Laravel app with Reputation Points & Achievements Badges support
License: MIT License
Hey, just wondering if this package have been tested with laravel octane.
Was about to implement this, and reviewing the migrations, noticed that columns like reputations.subject_id
, reputations.payee_id
and user_badges.user_id
make assumption about column types (e.g. these are integers or unsignedIntegers).
Was going to just edit the migration, but thought there might be some value in making this more introspective, as I'm sure I won't be the only person using UUIDs for some of these.
The first hurdle seems to be it's either/or not both so some structural change may be needed to extend this to mixed ID types. Perhaps a pivot table for this relationship might make more sense.
Next hurdle is these are in effect, foreign keys. Should we care about that and take advantage of things like cascading deletes?
Before I jump into all that, I thought it might be best to find out what your thoughts might be on these things. Happy to collaborate and submit PRs, but if it's not a direction you're interested in, let me know so I don't waste your time.
Thanks a lot for such awesome plugin. I feel it will be a breaking change but having ability to use badges for other models such as admins, groups, vendors, organizations etc. along with user model will be a huge benefit. Like this feature "Many To Many (Polymorphic)" (https://laravel.com/docs/6.x/eloquent-relationships#polymorphic-relationships). Thanks
hi again :)
I start to use this and it's amazing how easy to setup .
one thing I noticed is when Get reputation history with auth()->user()->reputations
I can access the payee
details , but not the subject
.
the $reputation->subject
always return null .
I think the relation is missing or I am missing some thing ?
public function subject() { return $this->belongsTo($this->subject_type, 'subject_id'); }
undoPoint(new PostCreated($post));
doesn't do anything. Am I missing something? I ended up creating another PointType class to just add negative points. However, it seems like I may be missing something. It would be nice to use the helper functions you created.
when i replace "Gamify" with "HasReputations" trait in user model to us Reputations only it give to me issue because it asking for
"Call to undefined method App\User::syncBadges()"
please help
Are there any plans to merge in the Laravel Shift pull request #60 ?
This package hasn't been updated in a while, is it considered abandoned?
Is there a limit on the number?For example, posting 3 times a day
Hi!
I'm trying to give points to a user after the user registers.
givePoint(new UserRegistered($user));
It does not work.
Any idea?
Hello,
Thanks for amazing plugin such a time saver.
I have a quick question.
I want to add a badge with
level 1
level 2
level 3
All of them have different descriptions.
for exc :
Level 1 : Has 100 post
Level 2 : Has 200 post
Level 3 : Has 300 post
My issues :
How to archive this with this plugin.
If i add description there is only one option.
I can make something like
if ($this->level == 1) $this->description = 'xx';
But as i see plugin does not read this value every time.
Thanks
Is it possible to award points when badge is earned?
Is there a method to check if user has particular badge earned?
Thanks,
I started using this package and when i create a badge and assign the points to the user it does not create or assign the badge to the user ( Like #9 )
php artisan cache:clear and php artisan cache:forget gamify.badges.all doesn't resolve the problem !
In database, user_badges table result (user_id, badge_id) is not added when I reached the second badge (2 points, the first badge is only 1 point)
I would like to have :
user_id 1 badge_id 1
user_id 1 badge_id 2
is it possible ?
Thanks for help !
I just started using this package and when i create a badge and assign the points to the user it does not create or assign the badge to the user.
I've created a kind of test point called TestPoint.
givePoint(new TestPoint($post));
Reputation is assigned correctly, I check it on database
The problem is that when the user reaches the reputation for example 20 the badge is not created in database and therefore is not assigned to the user.
<?php
namespace App\Gamify\Badges;
use QCod\Gamify\BadgeType;
class TestBadge extends BadgeType
{
/**
* Description for badge
*
* @var string
*/
protected $description = '';
/**
* Check is user qualifies for badge
*
* @param $user
* @return bool
*/
public function qualifier($user)
{
return $user->getPoints() >= 1;
}
}
I've created several badges and tested them and none of them work. even returning true in the qualifier function.
I would like to award a specific badge to a user inside my listener that listens to an event. Is there a method similar to givePoint() that i can use for this purpose?
For example assume i have a badge called AvatarUploadedBadge and i want to award it to the authenticated user first time they upload an avatar. Is there a method i can use inside my listener that listens to the AvatarWasUploadedEvent?
I have emailverified, firstcontribution and so on badges.
now i want to show modal like thing to notify users whenever they earned any badge..
`<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
class BadgeEarned extends Notification
{
use Queueable;
protected $badge;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($badge)
{
$this->badge = $badge;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'message' => 'You have earned ' . ${$this->badge->getName()} . ' badge.'
];
}
}
`
i have created notification, bt i couldnt find proper place to fire this notification because its generic notification whenever any badge is earned i want to show modal using vue for database notification.
Hi there,
Thanks for sharing this great package!
I'm having some difficulties trying to assign points to user, here's a snippet of my code:
$attributes = [
'user_id' => $id,
'project_id' => request()->project_id,
];
// Creates the project
$project = Project::create($attributes);
// Rewards points
givePoint(new ProjectCreated($project));
However, I'm getting the following error:
payee() method must return a model which will get the points.
Could you advise me on this?
Hi!
I'm trying to give points to an user first time after registered.
givePoint(new UserRegistered($user));
it work from postman but not from my webapp.
Any idea?
This is not a complaint but can be a suggestion.
I spent around an hour and half wondering why badges wouldn't work until I looked at the code in the service provider and realized that badges MUST be directly inside the Gamify/Badges directory. They cannot be inside folders within this directory.
So my suggestion is that this could be in the docs for anyone else running into this or the code can be changed a little bit to be able to dig into any folder structure within the Gamify/Badges directory.
Adding the folder structure search would be especially helpful for any larger app that has lots of badges and would like to organize them in folders within the Gamify/Badges directory.
Thank you for taking the time to read this!
I am getting this error, I have installed the package.
app.php constains "QCod\Gamify\GamifyServiceProvider::class"
composer.json contains "qcod/laravel-gamify": "^1.0",
Any idea how to solve this?
QCod\Gamify\Exceptions\InvalidPayeeModel
payee() method must return a model which will get the points.
I just want to know if we can perform complex queries inside the qualifier. For example
public function qualifier($user)
{
$categories = [];
$threads = $user->thread()->limit(5)->get();
foreach ($threads as $thread) {
if(in_array($thread->category->id, $categories)) {
continue;
}
array_push($categories, $thread->category->id);
}
if (count($categories) > 5) {
return true;
}
}
When using SQLite file as database, rolling back migration for a complete refresh using the following command:
php artisan migrate:refresh
This command throws the following error:
Rolling back: 2018_12_10_143555_create_gamify_tables
Rolled back: 2018_12_10_143555_create_gamify_tables
Rolling back: 2018_12_10_143555_add_reputation_field_on_user_table
Symfony\Component\Debug\Exception\FatalThrowableError : Class 'Doctrine\DBAL\Driver\PDOSqlite\Driver' not found
at /Users/Me/Sites/todo/vendor/laravel/framework/src/Illuminate/Database/SQLiteConnection.php:88
84| * @return \Doctrine\DBAL\Driver\PDOSqlite\Driver
85| */
86| protected function getDoctrineDriver()
87| {
> 88| return new DoctrineDriver;
89| }
90|
91| /**
92| * Get the database connection foreign key constraints configuration option.
Exception trace:
1 Illuminate\Database\SQLiteConnection::getDoctrineDriver()
/Users/Me/Sites/todo/vendor/laravel/framework/src/Illuminate/Database/Connection.php:885
2 Illuminate\Database\Connection::getDoctrineSchemaManager()
/Users/Me/Sites/todo/vendor/laravel/framework/src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php:267
Is there a way to automatically give a user a badge without having to give them a point and not doing a raw DB statement?
Hey!
I found this package by googling for laravel gamification and it has some nice features but the one it lacks which is essential to my use case is that the points should have an expiration date.
In order to do this, basically when fetching points we should only get those with dates superior to the expiration time.
The reason I need this is because the user will be able to exchange points for prizes, and we don't want them to keep getting lots of points and just buy lots os prizes at once.
I noticed that there is a point column in the user table, and this would need to be updated too when the points expire. So I think just having a reward history and fetching a sum
of the non-expired points would work.
What do you think?
Hi,
I read all documents but still have a problem when I try to populate the meta column in the reputations table while using
$user->givePoint(new PostCreated($post));
could somebody help me with this?
Thank you!
$payment->customer->user->undoPoint(new SuccessfulPayment($payment));
How to disable broadcast function of this package?
Hello,
When I try to do this :
$create_post = Posts::create(array(
'content' => $get_content,
'user_id' => Auth::user()->id
));
givePoint(new PostCreated($create_post));
It returns an error : payee() method must return a model which will get the points.
How to resolve this ? Thanks ! :)
Hello, it's not issue but I will ask to you
How to call Message after Reach a Badge?
I will try with Session::flash()
I'm trying to give points to the user when attaching invoice:
$in = $user->invoices()->attach($request->invoice);
$user->givePoint(new InvoicePoint($in));
I'm getting an error Initialize $subject field in constructor.
relation in User
Model :
public function invoices()
{
return $this->belongsToMany(Invoice::class, 'invoice_user');
}
Am I doing something wrong?
Hi Guys. I keep getting an error that says QCod\Gamify\Exceptions\InvalidPayeeModel payee() method must return a model which will get the points.
Config file:
payee_model' => '\App\Models\User
LeadCreated
public function payee()
{
return $this->getSubject()->user;
}
Lead Controller
$lead = Lead::create([
'first_name' => $postData['first_name'],
'last_name' => $postData['last_name'],
]);
$user = $request->user();
$user->givePoint(new LeadCreated($lead));
$post = auth()->user()->posts()->create($request->all()); // id: 1
$user = User::find(2); // id: 2
Why this method adds points to the user with the id: 1, and not on which it is pointing? What's the reason of the $user
, then?
$user->givePoint(new PostCreated($post));
How can I turn off the Info Logging, its filling up my log files?
[2022-03-03 23:49:38] production.INFO: Broadcasting [QCod\Gamify\Events\ReputationChanged] on channels [private-user.reputation.132] with payload:
{
"user": {
"id": 132,
"name": "##### Rosales",
"email": "[email protected]",
"email_verified_at": "2022-01-19T01:00:30.000000Z",
"created_at": "2022/01/21 04:12:31",
"updated_at": "2022/03/03 01:49:38",
"active": "1",
"is_master_admin": "0",
"properties": {
"dashboard": "8284",
I love how easy and simple it is to use this library, and to give points and bagdes to user. But I was wondering, would it be possible to use the library as is, to award badges based on, let's say "10 completed todos" or "Five day streak completing todos"?
If not, is this a feature you would be interested in developing?
possible to get reputation from $post? something like this. $post->reputations
public function reputations()
{
return $this->hasMany('QCod\Gamify\Reputation');
}
Hello! It is possible to bind the reputation to another user? I mean a user A voted a Post from user B. And i will give User B the reputation points.
Hello!
I was wondering what would be the best approach here to get the "ranking position" of a User A in comparison to all other users.
The goal would be to display #3
next to the user's name if he's 3rd in his total points.
User X has 1 point
User Y has 1000 points
User Z has 900 Point
User A has 800 Points -> he's in 3rd position in the global users ranking.
My first thought would be to run a daily cron job to aggregate each user's points in a new column on the users table. Then query all users ordered by this column ?
Thanks in advance
It would be great if this package update its support to Laravel 8!
Maybe i don't get it, but, when is called resetPoint(), then... probably it means, that all badges and reputations may be removed too, or not?
Trying to broadcast the ReputationChanged event is causing an exception in my app. Any tips to remove it?
Hi,
Please add laravel 9.0 support.
Hello
Please how to add a dynamic subject like , the user X created the post Y ?
And thanks
hi ,
I couldn't install the package on laravel 5.8.4
my composer : "laravel/framework": "~5.8.0",
I try it with : "laravel/framework": "5.8.*",
I got :
Problem 1 - Installation request for qcod/laravel-gamify ^1.0 -> satisfiable by qcod/laravel-gamify[1.0.0]. - Conclusion: remove laravel/framework v5.8.4 - Conclusion: don't install laravel/framework v5.8.4 - qcod/laravel-gamify 1.0.0 requires laravel/framework ~5.4.0|~5.5.0|~5.6.0|~5.7.0 -> satisfiable by laravel/framework[5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev]. - Can only install one of: laravel/framework[5.4.x-dev, v5.8.4]. - Can only install one of: laravel/framework[5.5.x-dev, v5.8.4]. - Can only install one of: laravel/framework[5.6.x-dev, v5.8.4]. - Can only install one of: laravel/framework[5.7.x-dev, v5.8.4]. - Installation request for laravel/framework (locked at v5.8.4, required as ~5.8.0) -> satisfiable by laravel/framework[v5.8.4].
Is there a way how to set qualifiers based on sum of specific points?
For example, qualifier as "Best author" based on Sum of published posts only?
Because qualifier based on sum of all points is not relevant in this case, right?
Love this package and would love to use it with Laravel 7
Payee is not getting the user parameter
This is my function
undoPoint(new PraiseCreated($praise, $this->task->user));
Even though I pass $this->task->user
the helper function is getting the authed user, so the points are going to the authed user instead of target user.
I found it by dumping dd($this->getSubject()->user);
in PraiseCreated Class
Hey,
Just came across this package and it looks promising but wanted to know if its still being maintained by the author since there are a few pr's and issues unanswered.
Would love to use it in one of my projects if it is.
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.