assada / laravel-achievements Goto Github PK
View Code? Open in Web Editor NEWLaravel 6+ User Achievements system.
Home Page: https://assada.github.io/laravel-achievements/
License: MIT License
Laravel 6+ User Achievements system.
Home Page: https://assada.github.io/laravel-achievements/
License: MIT License
Hello!
How about making name and description translatable fields? This is just suggestion for enhancement. Thank you!
This package is using a UUID for the primary key on the AchievementProgress
model but the keyType
is not getting properly set to string
on the model.
This is causing an odd bug when eager loading achievement.details
on a model that is related to AchivementProgress
thru the id
field.
For instance, with the following models:
class Reward extends Model
{
...
public function achievement(): BelongsTo
{
return $this->belongsTo(AchievementProgress::class);
}
...
}
class Player extends Model
{
use Achiever;
...
public function rewards(): HasMany
{
return $this->hasMany(Reward::class);
}
...
}
When running this query:
$player->rewards()->with('achievement.details')->get();
will cause the following queries to be run to eager load the AchievementProgress
models:
SELECT * FROM achievement_progress WHERE achievement_progress.id IN (0, 0, ...);
For most database engines, this would return 0 rows, but for MySQL, it actually returns all rows due to this issue.
Fortunately, Eloquent actually trims the results to the correct record causing the bug to go unnoticed for small datasets.
However, for large datasets it causes out of memory exceptions which is what led us to discovering this bug.
I believe setting keyType
to a string
on the model could possibly fix the SQL query so it properly includes the UUIDs:
SELECT * FROM achievement_progress WHERE achievement_progress.id IN ('783232ef-c7a0-49bb-ad62-73757a77f98f', ...);
This will ensure only the correct rows are returned.
I think a better fix would be to bump the minimum Laravel version to at least Laravel 9 and then refactor the AchievementProgress
model to use the new HasUuid
trait that was introduced in that version for this purpose. This would ensure ongoing compatibility with the core framework.
All support for Laravel 6 was dropped by the framework on September 6th 2022. It seems that packages should follow similar support timelines as the core framework. See https://laravel.com/docs/9.x/releases#support-policy
I'm happy to submit a PR that would raise the minimum to 9 (or 10) and adopt HasUuid
if the maintainers are likely to accept this change.
class UserMadeComment extends Achievement
{
/*
* The achievement name
*/
public $name = trans('achievements.made-first-comment-name');
/*
* A small description for the achievement
*/
public $description = trans('achievements.made-first-comment-description');
}
results in
[2021-03-14 16:26:54] prod.ERROR: Constant expression contains invalid operations {"userId":4,"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Constant expression contains invalid operations at /var/www/html/app/Achievements/UserMadeComment.php:23)
because trans won't work on constants
I can't install package because ramsey/uuid is older than my version.
Problem 1
- Conclusion: don't install assada/laravel-achievements 2.3.2
- Conclusion: don't install assada/laravel-achievements v2.3.1
- Conclusion: remove ramsey/uuid 4.1.0
- Installation request for assada/laravel-achievements ^2.3 -> satisfiable by assada/laravel-achievements[2.3.2, v2.3.0, v2.3.1].
- Conclusion: don't install ramsey/uuid 4.1.0
- assada/laravel-achievements v2.3.0 requires ramsey/uuid ^3.5 -> satisfiable by ramsey/uuid[3.5.0, 3.5.1, 3.5.2, 3.6.0, 3.6.1, 3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.8.0, 3.9.0, 3.9.1, 3.9.2, 3.9.3, 3.x-dev].
- Can only install one of: ramsey/uuid[3.5.0, 4.1.0].
- Can only install one of: ramsey/uuid[3.5.1, 4.1.0].
- Can only install one of: ramsey/uuid[3.5.2, 4.1.0].
- Can only install one of: ramsey/uuid[3.6.0, 4.1.0].
- Can only install one of: ramsey/uuid[3.6.1, 4.1.0].
- Can only install one of: ramsey/uuid[3.7.0, 4.1.0].
- Can only install one of: ramsey/uuid[3.7.1, 4.1.0].
- Can only install one of: ramsey/uuid[3.7.2, 4.1.0].
- Can only install one of: ramsey/uuid[3.7.3, 4.1.0].
- Can only install one of: ramsey/uuid[3.8.0, 4.1.0].
- Can only install one of: ramsey/uuid[3.9.0, 4.1.0].
- Can only install one of: ramsey/uuid[3.9.1, 4.1.0].
- Can only install one of: ramsey/uuid[3.9.2, 4.1.0].
- Can only install one of: ramsey/uuid[3.9.3, 4.1.0].
- Can only install one of: ramsey/uuid[3.x-dev, 4.1.0].
- Installation request for ramsey/uuid (locked at 4.1.0, required as ^3 || ^4) -> satisfiable by ramsey/uuid[4.1.0].
Is it possible to upgrade requirements of package?
Thanks.
When running the php artisan vendor:publish --provider="Assada\Achievements\AchievementsServiceProvider"
command, it responds with Publishing complete
. However, only the achievements.php
config file is published. And not the migration.
When trying to force run the command (php artisan vendor:publish --provider="Assada\Achievements\AchievementsServiceProvider" --force
, I am greeted with the following exception:
ErrorException
copy(): The second argument to copy() function cannot be a directory
at F:\Phoenix-Dev\base\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:302
298▕ * @return bool
299▕ */
300▕ public function copy($path, $target)
301▕ {
➜ 302▕ return copy($path, $target);
303▕ }
304▕
305▕ /**
306▕ * Create a symlink to the target file or directory. On Windows, a hard link is created if the target is a file.
1 F:\Phoenix-Dev\base\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php:302
copy("F:\Phoenix-Dev\base\vendor\assada\laravel-achievements\src/Migrations/0000_00_00_000000_create_achievements_tables.php", "F:\Phoenix-Dev\base\database\migrations")
2 F:\Phoenix-Dev\base\vendor\laravel\framework\src\Illuminate\Foundation\Console\VendorPublishCommand.php:221
Illuminate\Filesystem\Filesystem::copy("F:\Phoenix-Dev\base\vendor\assada\laravel-achievements\src/Migrations/0000_00_00_000000_create_achievements_tables.php", "F:\Phoenix-Dev\base\database\migrations")
What could be the cause of this problem?
Need to add Achive image in abstract class Achievement
Are the achievement files required for package to work correctly?
It would be easier for me to just seed achievements data directly into database and edit all details from there.
Thanks in advance for a fast help.
Looks like you forgot to update the dropTable names to use the config:
Schema::dropIfExists($this->achievement_progress);
Schema::dropIfExists($this->achievement_details);
Also Here:
$table->foreign('achievement_id')->references('id')->on($this->achievement_details);
is this compatible in php 7.4? i keep getting 502 when I'm querying the achievements
I'm creating an achievement from a user's first post, and I'm getting the status in the all achievements view where you can see the progress.
But when you call the view you always get that the first post was already created even if it hasn't.
I noticed and on the call
$details = $user->achievementStatus(new UserMadeFirstPost());
I'm assuming that at the same time it brings the achievement it also creates it, is that right?
This breaks the logic of the search because it always brings a positive.
Even after publishing the migration file the package's migration is still running. Thus giving me error of base table already exists.
0000_00_00_000000_create_achievements_tables .............................. 43ms DONE
2023_Feb_20_195204_create_achievements_tables .............................. 1ms FAIL
There is only one migration file in the migration folder.
Also, package migration class naming conventions need to be updated.
We want to use your HardFork in our project and wanted to check in how active this repo is due the infrequent pushes and open Issues since March. If we contribute Code - are the Pull Requests handled or would they remain undhandled?
cc direct @assada
Hello,
I suggest adding a documentation block about available relations.
It took me a while to find them so having such information at the start will save some time and effort for library users.
I am talking about those two relations as they are not described anywhere:
$user = User::find(1);
$achievements = $user->achievements;
foreach ($achievements as $achievement) {
dump($achievement->details); <- this one
dump($achievement->achiever); <- and that one too
}
Also, PHPStorm IDE is not suggesting them until you scan the library models directory with the command (which may be worth mentioning):
php artisan ide-helper:models --dir="vendor/assada/laravel-achievements/src/Model"
Thanks for reading my suggestions and I hope to get back from you soon.
In a MySQL database, the id
field type in the achievement_details
table is UNSIGNED BIG INT
because the $table->id();
command generates an unsigned big int field.
// This generates an UNSIGNED BIG INT column.
$table->id();
In the achievement_progress table
, the achievement_id
field is created as:
$table->unsignedInteger('achievement_id');
That causes a mismatch and MySQL won't create the foreign key.
It should be:
$table->unsignedBigInteger('achievement_id');
Hi I know this project is a bit old, but it does pretty much everything I need for what I am working on. I am having an issue with the listener not working, I am trying to make a Livewire component on the frontend that would display the achievements as you unlock them. The component looks like this:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Assada\Achievements\Event\Unlocked;
class Achievement extends Component
{
protected function getListeners()
{
return ['Unlocked' => 'display'];
}
public function render()
{
return view('livewire.achievement');
}
public function display($event)
{
dd($event);
}
}
I can see the event are being fired, but I am not able to have livewire listen to them, any idea what I am missing here?
Thanks again for your work on this project!
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.