Closed JBou closed 5 years ago
@JBou Thanks for pointing it out.
Would you please tell me why you need to change the controller. What do you want to solve?
I wanted to populate a select input using values from the database, so I needed to dynamically set the select options in the config.
Maybe there is a better way to change the values shown on the settings page programatically instead of hardcoding them in the config files?
class AppSettingController extends \QCod\AppSettings\Controllers\AppSettingController
{
/**
* Display the settings page
*
* @return \Illuminate\View\View
*/
public function index()
{
$years = Year::all()->mapWithKeys(function ($item, $key) {
return [$item->year => $item->year];
})->all();
config(['app_settings.sections.app.inputs.0.options' => $years]);
return parent::index();
}
}
Thanks, really this is a good feature to add, I will do it soon.
Its done 🎉
Now you can pass a closure in options
to populate all the options from database:
[
'type' => 'select',
'name' => 'year',
'label' => 'Year',
'rules' => 'required',
'options' => function() {
return Year::pluck('year', 'year')->toArray()
}
],
Have fun coding 👍
if I change the controller setting it doesn't have any effect because the controller in the routes are hardcoded
// Controller to show and handle save setting 'controller' => '\QCod\AppSettings\Controllers\AppSettingController'
https://github.com/qcod/laravel-app-settings/blob/4197ed8e6851eba4898ca226c9f343cb529adda5/src/routes/web.php#L3-L10