Reputation: 167
Trying to populate the dropdownlist from database. but there having some complication. Any help? This is based on laravel framework.
Part of the code
$projects = DB::table('projects')->where('users_id','=',Auth()->User()->id)->get();
foreach($projects as $project){
echo '
<option value="<?php $id = $project[id] ?>" name="parentProj">'
.$projectName = $project[id].
'</option>
';
}
Controller
public function index(){
$projects = DB::table('projects')->lists('id','projectName');
return view('pages.todo', ['projects'=> $projects);
}
Upvotes: 0
Views: 12539
Reputation: 701
Or you can use the Forms & HTML package from Laravel Collective: https://laravelcollective.com/docs/5.2/html#drop-down-lists
{{ Form::select('Projects', $projects)) }}
Upvotes: 0
Reputation: 7303
In your view:
<select name="parentProj">
@foreach($projects as $project)
<option value="{{ $project->id }}">{{ $project->projectName}}</option>
@endforeach
</select>
Upvotes: 3