Default field to select in Illuminate/html

Asked

Viewed 532 times

0

I have a problem and I have already searched the internet for the solution. Unsuccessful!

I have a form and inside it, a select filled automatically:

{!! Form::select('categoria_id', $categorias, null, ['class' => 'form-control']) !!}

Okay, it works. But I need to create a option with empty value. Type: "Select an option", here’s the problem. I’ve tried several ways, but what I found was for another version of Laravel and nothing done.

  • how is the object $categorias ? {!! Form::select('categoria_id', array_add($categorias, '', 'Selecione uma opção'), null, ['class' => 'form-control']) !!} will solve?

  • @Leandro Amorim, thanks for your help.

1 answer

2


This problem was recently solved in Laravel Collective.

{!! Form::select('size', ['dados' => 'no', 'seu' => 'select'], null, ['placeholder' => 'Selecione uma opção']) !!}

If you are not using it in your application, I recommend using it.

The component Form was removed from Laravel core from version 5, as you can see in the documentation.

If you’re using Form or HTML helpers, you will see an error stating class 'Form' not found or class 'Html' not found. The Form and HTML helpers have been deprecated in Laravel 5.0; However, there are community-driven Replacements such as those maintained by the Laravel Collective.

Check whether your composer.json is using the laravelcollective/html. If no follow the step by step of your installation.

  • Thanks for the help.

Browser other questions tagged

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