php - Laravel Form Facade For Select with extra Tag on one option -


i have select option in html form select.

 <select name="position" id="position" class='position metadata form-control' data-parsley-required data-parsley-required-message="please select 1 position">              <option value="">select position</option>             {{ $options = app\metadata::all()->where('category','position') }}              @foreach($options $option)                 <option value="{{$option->item}}">{{$option->item}}</option>                 @endforeach             <option value="1" mytag='position'>define new</option>         </select>  

the form facade work this

$options = app\metadata::where('category', 'department')->orderby('item')->pluck('item', 'item');    $options->prepend('define new', '1');    $options->prepend('select department', '0');     ?>                                                                                               {!! form::select('department', $options , null, ['class' => 'department metadata form-control', 'id'=>'department']) !!} 

the problem how add mytag $options->prepend('define new', '1'); last option on select in form facade

adding additional elements laravel's collection:

you should in controller:

$metadataoptions = app\metadata::orderby('item')->pluck('item');  //this first option $metadataoptions->prepend('select department', '0');  //this last option  $metadataoptions->push('define new', '1'); 

then return view $metadataoptions:

return view('insert_your_view')->withoptions($metadataoptions);

and in view pass $options form::select():

{!! form::select('department', $options , null, ['class' => 'department metadata form-control', 'id'=>'department']) !!} 

adding custom attributes option:

you need define own "type" of element form. can achieved using form::macro: https://laravelcollective.com/docs/5.2/html#custom-macros


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -