Laravel 5.2 - 从数据库中填充选择选项

时间:2016-02-16 00:52:54

标签: php laravel select options dropdown

尝试从数据库填充下拉列表。但有一些并发症。有帮助吗?这是基于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);
}

2 个答案:

答案 0 :(得分:2)

在您看来:

func presentWinningAlert(alert: String) 
{
  let presentAlert = UIAlertController(title: "The Winner is \(alert)", 
    message: nil, 
    preferredStyle: .Alert)
  let reset = UIAlertAction(title: "Reset", 
    style: UIAlertActionStyle.Default, 
    handler: clearLabels)
  presentAlert.addAction(reset)
  presentViewController(presentAlert, 
    animated: true, 
    completion: nil)
}

答案 1 :(得分:0)

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

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