[Bug]: Unknown named parameter $to
im-aeo opened this issue · 11 comments
What happened?
How to reproduce the bug
When i add the points needed to level up to the next level i get this.
$amount = 200;
$Pointsamount = 400;
$user->coins += $amount;
$user->addPoints($Pointsamount);
Package Version
^1.2.3
PHP Version
8.2.7
Laravel Version
^10.0
Which operating systems does with happen with?
Linux
Notes
No response
I cannot recreate this...
Are you sure you're on a version of PHP that supports named arguments?
You could overwrite the levelUp
method on your Model and remove the named argument and see if that works.
Sorry couldn't be more help.
I am on php 8.2.7, as I remember this version supports named arguments.
how may I go about overwriting it.
Yeah that should support it... very odd.
In your Model (where you use the GiveExperience
trait, add the levelUp
method from the Trait and remove the named argument.
Or, if you want to clean things up, you could create a Trait and extend the GiveExperience
trait and add it in there.
Ok i'll try that. Thank you so much for the help
GiveExperience
public function levelUp(int $to): void
{
if (config(key: 'level-up.level_cap.enabled') && $this->getLevel() >= config(key: 'level-up.level_cap.level')) {
return;
}
$this->fill(attributes: ['level_id' => $to])
->save();
$this->experience->status()->associate(model: $to);
$this->experience->save();
// Fire an event for each level gained
for ($lvl = $this->getLevel(); $lvl <= $to; $lvl++) {
event(new UserLevelledUp(user: $this, level: $lvl));
}
}
Remove the to imports correct?
oh there is one thing that could be causing this.
I don't know how to use the level facade so i seeded the database.
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class LevelSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run() : void
{
$baseExperience = 250;
$levels = [];
// Add level 1 with null next_level_experience
$levels[] = [
'level' => 1,
'next_level_experience' => null,
];
// Loop through levels starting from 2 (skip level 1)
for ($level = 2; $level <= 200; $level++) {
$experience = round($baseExperience + (0.3 * ($level - 1)));
$baseExperience = $experience;
$levels[] = [
'level' => $level,
'next_level_experience' => $experience,
];
}
// Insert all levels in a single batch for efficiency
DB::table('levels')->insert($levels);
}
}
Argh... sorry, I've given you some bad info (long day...)
It is the PointsIncreasedListener
where you got the error, but I'm unsure how you'd overwrite that... seems a lot of work for something that technically isn't a bug in the first place.
A Level can be added with the facade:
Level::add([
'level' => 2,
'next_level_experience' => 200,
]);
Argh... sorry, I've given you some bad info (long day...)
It is the
PointsIncreasedListener
where you got the error, but I'm unsure how you'd overwrite that... seems a lot of work for something that technically isn't a bug in the first place.A Level can be added with the facade:
Level::add([ 'level' => 2, 'next_level_experience' => 200, ]);
No Worries. But i do wonder how to fix this.
Argh... sorry, I've given you some bad info (long day...)
It is the
PointsIncreasedListener
where you got the error, but I'm unsure how you'd overwrite that... seems a lot of work for something that technically isn't a bug in the first place.A Level can be added with the facade:
Level::add([ 'level' => 2, 'next_level_experience' => 200, ]);
oh but how so in my case. i want to make 200 levels seeded with a slow increase in exp. You know just to automate the process.
I'm not 100% what you mean, but some kind of loop I imagine in a Seeder.
I'm gonna close the issue now as it isn't something I can help further with or fix.
Good luck with your journey.
I'm not 100% what you mean, but some kind of loop I imagine in a Seeder.
I'm gonna close the issue now as it isn't something I can help further with or fix.
Good luck with your journey.
thank you