I know there is already a question on stackoverflow about populating select box , but there are answers given using form:select() facade
I want to populate select box but not using form facade. I did this and it worked for me
In controller
public function create()
{
$states=General_states::all('state_name','state_id');
return view('admin.addcity',compact('states'));
}
In view
<select class="form-control" name="movie_language">
@foreach($states as $data)
<option value="{{ $data->state_id }}">{{ $data->state_name }} </option>
@endforeach
</select>
But I want to use ::lists here like this
In Controller
public function create()
{
$states=General_states::lists('state_name','state_id');
return view('admin.addcity',compact('states'));
}
But In view I am getting error message as trying to get the property of Non Object. Help me so that I can use lists in controller and populate select box in view without using {{form::select() }}
if you don't need filtering here is a short hand way.suppose your General_states
namespace is App\\
{!! Form::select('movie_language', App\General_states::lists('state_name','state_id'),'', ['class'=>'form-control']) !!}
or if you want to another way just send me the dump of after changing your code like this and executing.
public function create()
{
$states=General_states::lists('state_name','state_id');
dd($states);
return view('admin.addcity',compact('states'));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.