【问题标题】:Laravel populate form with DB data but showing all users dataLaravel 使用数据库数据填充表单,但显示所有用户数据
【发布时间】:2016-02-01 18:37:15
【问题描述】:

我读到了这个Populating a dropdown menu with database results in Laravel 4

并且能够从 Laravel 中的 MySQL 数据库中填充选择抓取值 然而,这不限于属于登录用户的数据。 任何点击赞赏 `Route::get('applications', array('before' => 'auth', function() { //返回视图::make('applications'); //注释掉 10/31/15

      // 10/31/15 create the array to hold companies from companies table - $company_lists

      //return view applications plus the array

      $company_lists = Company::lists('company', 'id');  /// 10/31/
       $resume_lists = Resume::lists('name', 'user_id');  /// 11/1/15


      return View::make('applications', array('company_lists' => $company_lists), array('resume_lists' => $resume_lists));  ///10/31/15
    }
)

);`

【问题讨论】:

    标签: php mysql laravel


    【解决方案1】:

    您似乎缺少 where 子句。我不太明白你的表结构,所以不完全是哪些位需要 where 子句,但我想这些方面的东西会更好:

    $user = Auth::user();
    $resume_lists = Resume::where('user_id', '=', $user->id)->lists('name', 'user_id');
    

    【讨论】:

    • 你确定可以在里面使用where子句吗?
    • 相当肯定,这是在文档中:$model = User::where('votes', '>', 100)->get(); 仍然 laravel 有一些有趣的交互,也许它不喜欢“列表”
    猜你喜欢
    • 2018-10-13
    • 2014-10-23
    • 2019-01-29
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    相关资源
    最近更新 更多