Jump to content
  • 0

Create dropdown based on info from database


DennisHermannsen

Question

Hi,

I've been trying to create a dropdown for our module based on data from the database. I want to get the admin names, and these should be selectable in the dropdown menu.

function mymodule_config()
{
	$admins = Capsule::table('tbladmins')->get();
	foreach($admins as $adminNames){
		$admin = $adminNames->username;
		return [
        // Display name for your module
        'name' => 'Test',
        // Description displayed within the admin interface
        'description' => 'Test',
        // Module author name
        'author' => 'Test',
        // Default language
        'language' => 'english',
        // Version number
        'version' => '0.1',
			'fields' => [
				// the dropdown field type renders a select menu of options
				'AdminSend' => [
					'FriendlyName' => 'Admin to create ticket',
					'Type' => 'dropdown',
					'Options' => $admin,
					'Description' => 'Choose one',
				],
			]
		];
	} 
}

Above is what I've tried, and it didn't think it would work - and it didn't. What is the proper way to do this?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

I might have this one figured out - if anyone knows of a better way, please let me know.

function mymodule_config()
{
	$activeAdmins = array();
	$admins = Admin::all();
	echo $admins->username;;
	foreach ($admins as $key => $value) {
		$activeAdmins[] = $value->username;
	}
	$admins = implode(', ', $activeAdmins); 
	return [
			// Display name for your module
			'name' => 'Test',
			// Description displayed within the admin interface
			'description' => 'Test',
			// Module author name
			'author' => 'Test',
			// Default language
			'language' => 'english',
			// Version number
			'version' => '0.1',
				'fields' => [
					// the dropdown field type renders a select menu of options
					'AdminSend' => [
						'FriendlyName' => 'Admin to create ticket',
						'Type' => 'dropdown',
						'Options' => $admins,
						'Description' => 'Choose one',
					],
				]
			];
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated