The request is quite the same as I made in a previous topic but instead of getting the languages options I need to retrieve user information from a database (sqlite) with a “value” =>" userInDatabase.id()" and “text” => userInDatabase.email to generate the dropdown.
So… following the Extended products area demo code, I would add inside classes/Product.php the follwing:
public static function getUser(): array
{
Db::connect([
'database' => dirname(__DIR__, 1).'/db/user.sqlite',
'type' => 'sqlite'
]);
$customers = Db::select('users', '*', null, 'email DESC')->toArray();
return array_map(function($customer) {
return (object) $customer;
}, $customers);
}
and adding a field inside dialogs/fields.php :
'users' => [
'label' => 'Users',
'type' => 'select',
'options' => Products::getUser()->values(fn($user) => [
'value' => $user->id(),
'text' => $user->email()
])
],