Comments (5)
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();
}
}
from laravel-app-settings.
@JBou Thanks for pointing it out.
Would you please tell me why you need to change the controller. What do you want to solve?
from laravel-app-settings.
Its fixed in 1.0.3
docs here
from laravel-app-settings.
Thanks, really this is a good feature to add, I will do it soon.
from laravel-app-settings.
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 👍
from laravel-app-settings.
Related Issues (20)
- Declaration of Symfony\Component\Translation\TranslatorInterface::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) HOT 5
- Use in Middleware HOT 2
- support type=url
- Your configuration files are not serializable HOT 6
- Laravel 7 HOT 2
- unable to locate publishable resources HOT 1
- Default value for removed image is different from an image that was never set HOT 2
- php8 version HOT 5
- Select multiple not working
- when saving image and remove it the default value set null and cant get the default value how can i fix it
- Can't get setting on services.php
- Undefined variable: settingsUI (View: /project directroy/resources/views/vendor/app_settings/_settings.blade.php)
- Cannot declare class CreateSettingsTable, because the name is already in use
- Not able to install HOT 1
- Is it support Php 8 HOT 2
- Global Settings HOT 1
- Translation
- [Help] Separate into multiple controllers
- config not serialisable when doing config:cache
- Image type not compatible with Vapor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-app-settings.