php - Laravel 使用数据库数据填充表单但显示所有用户数据

标签 php mysql laravel

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

并且能够从 Laravel 中的 MySQL 数据库中填充选择的抓取值 但是,这并不限于属于登录用户的数据。 任何命中赞赏 `Route::get('applications', array('before' => 'auth', function() { //返回 View::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
    }
)

);`

最佳答案

您似乎缺少 where 子句。我不太了解你的表结构,所以不完全是哪些位需要 where 子句,但我想按照这些思路做的事情会更好:

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

关于php - Laravel 使用数据库数据填充表单但显示所有用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33468123/

相关文章:

MySQL 错误 1442 使用 2 个触发器更新 2 个不同数据库上的 2 个表的字段

php - preg_replace() 在 MySQL 表中查找匹配项

php - Queue:push() 在 Laravel 5 中被同步处理

PHP str_replace 任意数字模式

mysql - 在新的 EC2 实例中启动 mysql 会抛出 "can' t connect through socket"错误

laravel - Blade View 不反射(reflect)变化

php - 如何更改 token guard 中的 api_token 列

php - Cron 在 ubuntu (digitalocean) 中不起作用

php - 自定义错误页面不适用于 Apache 和 nginx 设置的 .htaccess

php - DateControl yii 2 中的预选值