问题
i want to show the database values in drop down..i tried a lot but it's not working for me.. i am getting errors i don't know where i mistaken..i am new to laravel..please help me where i mistaken..
view:
<div class="form-group">
<label for="name" class="col-md-4 control-label">User type</label>
<div class="col-md-6">
<?php
{!!Form::select('user_type_id[]', $usertypes_list, $thing->user_type->pluck('id'), ['class' => 'form-control'])!!}
;?>
</div>
Controller:
public function get() {
$usertypes_list = User_type::lists('id', 'type');
return view('edit')->compact('user_type');
}
Can anyone help me... Thanks in advance.
回答1:
run composer require "laravelcollective/html":"^5.4"
to add laravelcollective
to your project as Form::select
is no longer available in laravel 5+
and have a quick look on this laravelcollective Doc.s
Edit:
in your controller you've to pass $usertypes_list
so the function should be
public function get() {
$usertypes_list = User_type::pluck('id', 'type');
return view('edit')->compact('usertypes_list');
}
then your view should looks like:
<div class="form-group">
<label for="name" class="col-md-4 control-label">User type</label>
<div class="col-md-6">
{!!Form::select('user_type_id[]', $usertypes_list, null, ['class' => 'form-control'])!!}
</div>
来源:https://stackoverflow.com/questions/42898516/how-to-populate-database-values-in-dropdwon-in-laravel