i've created a field into settingsPage
that add a select input with a country code value. Now i want to allow user to set own country code, and re-use this value on frontend.
i've created a migrations
<?php
namespace Justoverclock\CountryFlags;
use Illuminate\Database\Schema\Blueprint;
use Flarum\Database\Migration;
return Migration::createTable(
'country_code',
function (Blueprint $table) {
$table->increments('id');
// created_at & updated_at
$table->timestamps();
}
);
but i'm stucked with Listeners and serializers.
i'm trying to peak at fof user bio code but is different. my questions are:
- my field have a "save" button, but idk how to set the onclick event for that
- i don't know how make a correct listeners, i've tried
<?php
namespace Justoverclock\CountryFlags\Listeners;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Event\Saving;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class SaveCountryFlag
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;
public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}
/**
* @param Saving $event
*
* @throws \Flarum\User\Exception\PermissionDeniedException
*/
public function handle(Saving $event)
{
$user = $event->user;
$data = $event->data;
$actor = $event->actor;
if (isset($attributes['CountryFl'])) {
$actor->assertCan('editCountryFlag', $user);
$user->save();
}
}
}
any help is appreciated, is my first time with backend