Laravel 5.2 - 从数据库填充 select 选项

Laravel 5.2 - Populate select options from database

正在尝试从数据库填充下拉列表。但有一些并发症。有什么帮助吗?这是基于 laravel 框架。

部分代码

$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>
                                  ';
                        }

控制器

public function index(){
    $projects = DB::table('projects')->lists('id','projectName');

    return view('pages.todo', ['projects'=> $projects);
}

在您看来:

<select name="parentProj">
    @foreach($projects as $project)
     <option value="{{ $project->id }}">{{ $project->projectName}}</option>
    @endforeach
</select>

或者您可以使用来自 Laravel Collective 的 Forms & HTML 包: https://laravelcollective.com/docs/5.2/html#drop-down-lists

{{ Form::select('Projects', $projects)) }}