I haven’t learned Laravel systematically, I’m just trying to imitate other extensions to make my extension.
What I want to achieve is: add a button in the SettingsPage(done), onClick, do some logic, and update the column 'test' in the table 'users'.
I checked other extensions's code like 'NickName' and 'Suspend', and i imitate the following codes to do that, but it doesn't work.
/js/forum/index.js
app.initializers.add('test-test', () => {
//.........
function saveChanges() { //onclick={() => saveChanges()
app.session.user.save({test: 1}) //change to '1'
}
/extend.php
namespace Flarum\MyExtension;
use Flarum\Extend;
use Flarum\User\Event\Saving;
return [
(new Extend\Event())
->listen(Saving::class, SaveTestToDatabase::class)
];
/src/SaveTestToDatabase.php
<?php
namespace Flarum\MyExtension;
use Flarum\User\Event\Saving;
use Illuminate\Support\Arr;
class SaveTestToDatabase{
public function handle(Saving $event)
{
//I don't know what to do here
}
}
And how to update and query data out of the "users" table?
I have a small suggestion I hope you can refer to. For the pre-installed extensions, I hope you can write more comments. This is useful for people who do not want to systematically learn web development to develop some simple Flarum extensions.