How to concatenate value into a dropdownlist in Laravel 5?

Asked

Viewed 161 times

1

How to add the first default value to a dropdownlist? I tried to do this way:

{!! Form::select('Usuario.est_id',array('null' => 'Selecione') + $estados, null, ['class' => 'form-control']) !!}

but it returns me the error: Fatalerrorexception in 30aae33d562adffd11ade38d9100e329 line 26: Unsupported operand types

The $states are a Collection.

1 answer

2


do so

{!! Form::select('Usuario.est_id',array_merge(['null' => 'Selecione'],
       Estado::orderBy('uf')->lists('uf', 'est_id')), null, ['class' => 'form-control']) !!}
  • Didn’t work it returns me array_merge(): Argument #2 is not an array (View: C: wamp www Cristiana Resources views usuarios index.blade.php)

  • your second argument is not Arrau, so you make $state->toArray();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.