AuthController.php - 我不知道如何以这种方式将数据传递给视图。我应该在这里做这个还是应该创建一个新的控制器?
protected function create(array $data)
{
$departments = Department::lists('deptName', 'id');
return User::create([
'name' => $data['name'],
'deptartmentId' => $data['dept'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
我的观点
<div class="form-group">
{{ Form::select('dept', $departments) }}
</div>
我也试过创建一个函数,但是我得到一个错误,说在视图文件中未定义$ departments变量
public function getDepartments()
{
$departments = Department::all(['id', 'deptName']);
return view('AuthController.getDepartments', compact('id', 'departments'));
}
答案 0 :(得分:1)
$ departments变量在视图文件中未定义,因为您没有使用视图返回$ departments集合,
这将起作用
public function getDepartments()
{
$departments = Department::all(['id', 'deptName']);
return view('folder.theviewname')->with('departments',$departments);
}