Code Monkey home page Code Monkey logo

Comments (5)

JBou avatar JBou commented on June 11, 2024 1

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.

saqueib avatar saqueib commented on June 11, 2024

@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.

saqueib avatar saqueib commented on June 11, 2024

Its fixed in 1.0.3 docs here

from laravel-app-settings.

saqueib avatar saqueib commented on June 11, 2024

Thanks, really this is a good feature to add, I will do it soon.

from laravel-app-settings.

saqueib avatar saqueib commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.