2

I have a select field in my form for selecting admin roles.I need to set a default value for that select field like 'Select Role'.I am using Laravel 5.2 and collective form builder class.here is my code

{!! Form::select('role_id',App\Role::orderBy('name')->lists('label','id'),$roleId,array('class'=>'form-control col-md-7 col-xs-12','id'=>'role_id')) !!}
Sandeep Bhaskaran
  • 621
  • 1
  • 7
  • 14

1 Answers1

1

Third argument is a default for select list, so $roleId should contain default role ID in this case.

If it doesn't work, you should check what $roleId contains and also look into HTML generated by Form::select clause to find a problem.

Update

To add Select Role default value, do this before Form::select clause:

<?php
    $rolesList = App\Role::orderBy('name')->lists('label','id');
    $rolesList[0] = 'Select Role';
    ksort($rolesList); // Will resort list.
?>
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279