25

Using Laravel 4's Form class, we can create a list using

 {{ @Form::select('colors', Colors::all()), $color }}

Question: How can we add the attribute disabled using Blade without having to rewrite the clean Blade syntax into the usual ugly form?

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830

3 Answers3

35

Just add array('disabled') in the end like:

{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}
The Alpha
  • 143,660
  • 29
  • 287
  • 307
JustinHo
  • 4,695
  • 3
  • 20
  • 20
19

This should do the work.

 {{ @Form::select('colors', Colors::all()), array(
    'disabled' => 'disabled',
    'class'    => 'myclass'
    ) }}
PJunior
  • 2,649
  • 1
  • 33
  • 29
1

Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments are @Form::select('name', $optionsArray, $selectedOption, ['disabled']).

So if you're prepopulating form with @Form::model() you should do @Form::select('name', $optionsArray, null, ['disabled']) - array with 'disabled' has to be 4th parameter.

Edmund Sulzanok
  • 1,883
  • 3
  • 20
  • 39