我正在尝试验证登录表单并在页面上显示错误。但是当我点击登录时,我收到422错误。
任何帮助都将不胜感激。
这是我的handleLogin函数,用于在单击登录按钮时处理进程。
public function handleLogin(Request $request){
/* validate user */
$this->validate($request, User::$login_validation_rules);
$data = $request->only('email', 'password');
if(\Auth::attempt($data)){
return redirect()->route('home');
}
return back()->withInput();
}
以下是routes.php
Route::get('/login', ['as' => 'login', 'uses' => 'LoginController@login']);
Route::post('/handleLogin', ['as' => 'handleLogin', 'uses' => 'LoginController@handleLogin']);
Route::get('/home', ['as' => 'home', 'uses' => 'UsersController@home']);
Route::get('/logout', ['as' => 'logout', 'uses' => 'LoginController@logout']);
Route::resource('users', 'UsersController', ['only' => ['create', 'store']]);
以下是登录表单。
@extends('master')
@section('content')
<h2> Login </h2>
@if(count($errors))
<div class="alert alert-danger">
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
{!! Form::open(array('route' => 'handleLogin')) !!}
<div class="form-group">
{!! Form::label('email') !!}
{!! Form::text('email', null, array('class' => 'form-control')) !!}
</div>
<div class="form-group">
{!! Form::label('password') !!}
{!! Form::password('password', array('class' => 'form-control')) !!}
</div>
{!! Form::token() !!}
{!! Form::submit('Login', array('class' => 'btn btn-default')) !!}
{!! Form::close() !!}
@stop