【发布时间】:2018-09-11 01:00:36
【问题描述】:
我正在尝试从我的 laravel 网站禁用密码验证系统。我想只使用他们的名字和姓氏登录我的用户。明智的形式,明智的注册和明智的数据库,密码字段已被完全删除。但是在登录控制器中,我遇到了一些问题,它似乎不起作用。这是我的代码:
public function login(Request $request)
{
$first_name = $request->first_name;
$last_name = $request->last_name;
$user = User::where(['first_name' => $first_name, 'last_name' => $last_name])->first();
if (!$user) {
return redirect()->back()->withInput($request->only('first_name', 'last_name'))->withErrors([
'first_name' => 'We could not find you in our database, if you think this is a mistake kindly contact the site administrators',
]);
}
Auth::login($user);
return redirecte('/');
}
在上面的代码中,我收到了错误消息
我们无法在我们的数据库中找到您,如果您认为这是一个错误,请联系网站管理员
无论我在表单中插入什么信息(真或假)。
【问题讨论】:
-
您是否尝试将
if (!$user)更改为if (empty($user))。这就是我通常用来检查模型是否为空的方法 -
如果根据您的代码收到该错误意味着,他们不存在具有该名和姓的此类用户