This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Hello,
I'm trying to understand how to create a backend field in my newly created plugin that will dynamically list all users of the platform.
This said, my goal is to submit a notifications form to create a notification, and I will process that form at creation to fill another table named notification_recipients that contains the notification id, user_id, and some extra boolean fields (like archived, seen, etc).
I've read, searched, and came to understand I have to use relations, but didn't get any result since the relation I'm trying to set is only for selecting the users from a list. This means we have three tables : notifications, notification_recipients and the common users table.
Could you help me figure it out ? :)
Thank you very much !
Last updated
Update : I added a Checkbox List named "users".
For now, I got it working by doing this in the Model used for the form:
use RainLab\User\Models\User;
...
public function getUsersOptions($value, $formData)
{
$users = User::all();
$mapped = $users->mapWithKeys(function ($item) {
return [$item['id'] => $item['name']];
});
return $mapped;
}
It worked great and I'm getting all users with their ids.
I added "_" to make the field purgeable, so it doesn't get processed to the table.
Last updated
1-2 of 2