我使用标准laravel 5.4 authentication系统,但在登录页面上进行了更改。
我希望我的登录页面在索引上,所以我手动添加了身份验证路由:
//I only changed the get route since I only wanna change the action for the view
Route::get('/', [
'as' => 'login',
'uses' => 'TestController@index'
]);
Route::post('login', [
'as' => '',
'uses' => 'Auth\LoginController@login'
]);
这很好用。 localhost/
将我带到了我的页面。
现在我使用与laravel Auth:
生成的页面相同的页面<form action="{{route('login')}}" method="POST">
//Standard input fields with the same names etc...
<input type="email" name="email">
<input type="password" name="password">
<input type="submit" name="submit">
<input type="checkbox" name="remember"> //etc..
</form>
我根本没碰到控制器:
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = 'home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
无论我是否提供正确或错误的登录凭据都无关紧要,它只是刷新页面。
我在这里做错了什么?注册等工作完美。相同的形式和路线的路径:
Route::get('register', [
'as' => 'register',
'uses' => 'Auth\RegisterController@showRegistrationForm'
]);
Route::post('register', [
'as' => '',
'uses' => 'Auth\RegisterController@register'
]);
将登录页面更改为索引页面时是否忘记了某些内容?
答案 0 :(得分:2)
这是因为您尝试将POST请求发送到同一页面,因为route('login
)`==您的主页。
更改
<form action="{{route('login')}}" method="POST">
通过
<form action="{{url('login')}}" method="POST">
您不需要始终使用命名路线,有时更容易使用url()
。
这样做:
Route::get('/', [
'as' => 'login',
'uses' => 'TestController@index'
]);
Route::post('/', 'Auth\LoginController@login');
和
<form action="{{ url('/') }}" method="POST">