Я использую laravel 5. Мне нужно войти в систему с помощью имени пользователя или электронной почты. Я изменяю следующий фрагмент кода из файла AuthenticatesAndRegistersUsers.php:
public function postLogin(Request $request)
{
$this->validate($request, [
'email' => 'required', 'password' => 'required',
]);
$credentials = $request->only('email', 'password');
if ($this->auth->attempt($credentials, $request->has('remember')))
{
return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())
->withInput($request->only('email', 'remember'))
->withErrors([
'email' => 'These credentials do not match our records.',
]);
}
со следующим кодом.
public function postLogin(Request $request)
{
$field = filter_var($request->input('loginfield'), FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
$this->validate($request, [
'loginfield' => 'required', 'password' => 'required',
]);
if ($this->auth->attempt([$field=> $request->only('loginfield'), 'password'=>$request->only('password')], $request->has('remember')))
{
return redirect()->intended($this->redirectPath());
}
return redirect($this->loginPath())
->withInput($request->only('loginfield', 'remember'))
->withErrors([
'email' => 'These credentials do not match our records.',
]);
}
Я также изменил код из login.blade.php соответствующим образом. Но когда я передаю ему учетные данные. Выдает ошибку "Обязательно поле электронной почты". В login.blade.php я сделал два изменения. 1. изменил тип ввода с «электронной почты» на «текст» и 2. имя с «электронной почты» на «поле входа». Я делаю что-то не так?
App\Http\Requests\LoginRequest
- person Ben Swinburne   schedule 18.02.2015