How can I create a dropdown list with colored <option> elements in Laravel 5.4?

I want to create a dropdown in Laravel 5.4 that has a different background color for each item <option>

.

I have read and tried the following:

None of them worked for me. I always get The colorSelect method does not exist. mistake.

If I just want to use Form::macro

it says the method doesn't exist. I found several articles on creating your own macros, but none of them said where to add these macros.

+3


source to share


1 answer


You can add a macro by following these steps:



  • Create a new provider called MacroServiceProvider.
  • Add your macro to the registration method.

    public function register()
    {
        FormBuilder ::macro('time', function ($name, $default, $otherparams, ...) 
        {
            ....
        }
    }
    
          

  • Register MacroServiceProvider in your app.config file.

    'providers' => [
    
    /*
     * Laravel Framework Service Providers...
     */
     \App\Providers\MacroServiceProvider::class,
    'AltThree\Bus\BusServiceProvider',
    'Illuminate\Notifications\NotificationServiceProvider',
    
          

  • Run the linker dump-autoload -o on a command line open in your project folder.

  • You can now use your macro in your view files.

0


source







All Articles