How to make a dynamic selection in laravel 5.7 laravel collective?


Veran I have a registration form to my table Inmueble , and one of the fields is its location, the ubicacion is also a table in my database, the fields in the table ubicacion are id and nombre , I need that the select appears the nombre , and the value that I sent is the id , but I do not know how to do it in laravel collective.

Currently my code in the controller is as follows:

$ubicaciones= Ubicacion::pluck('nombre', 'id');

I am receiving it at the hearing and I am showing it this way

{!! Form:: select('ubicacion', $ubicaciones, null, ['class' => 'select  ph9  sm10  md10  lg10', 'placeholder' => 'Ubicación']) !!}

But at this moment when I register all the information in the form and give the registration button, laravel gives me the registration error saying that the location field is null, so I do not know what to do.

asked by Santiago Bueno 12.12.2018 в 18:51

1 answer


In laravel collective it is:

{!! Form::select('ubicacion', $ubicaciones, null, ['class' => 'ubicacion', 'id' =>'ubicacion']) !!}

Where $ locations contains all the locations you're going to list.

answered by 12.12.2018 в 20:20