本文共 1826 字,大约阅读时间需要 6 分钟。
路线文件
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/' , ['as' => '/', 'uses' => 'LoginController@getlogin']);
Route::post('/Login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
Route::get('/login', array('as' => 'login', 'uses' => 'LoginController@getLogin'));
Route::group(['middleware'=>['authen','roles' ]], function(){
Route::get('/logout' , ['as' => 'logout' , 'uses'=> 'LoginController@getLogout']);
Route::get('/dashboard',['as'=> 'dashboard', 'uses'=> 'DashboardController@dashboard']);
});
的LoginController
class LoginController extends Controller{
use AuthenticatesUsers;
protected $username = 'username';
protected $redirectTo = '/dashboard';
protected $guard = 'web';
public function getLogin()
{`enter code here`
if (Auth::guard('web')->check()){
return redirect()->route('dashboard');
}
return view('login');
}
public function postLogin(Request $request)
{
$auth = Auth::guard('web')->attempt(['username'=>$request->username, 'password'=>$request->passwod , 'active' => 1]);
if ($auth) {
return redirect()->route('dashboard');
}
return redirect()-> route('/');
}
public function getLogout()
{
Auth::guard('web')->logout();
return redirect()->route('/');
}
}
每当我尝试登录时,网址都会转到“http://localhost:8000/login ”和RouteCollection.php第179行中的NotFoundHttpException:发生错误.
我尝试了很多时间,但我无法登录Laravel.
刀片文件
@extends('layouts.app')
@section('content')
{
{ csrf_field() }}Username
@if ($errors->has('username'))
{ { $errors->first('email') }}
@endif
Password
required>
@if ($errors->has('password'))
{ { $errors->first('password') }}
@endif
Remember Me
Login
@endsection
最佳答案 从表单的action属性中删除最后一个空格:
应该:
另外,在登录后路线中使字母L变小.
Route::post('/Login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
应该
Route::post('/login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
转载地址:https://blog.csdn.net/weixin_32058931/article/details/115954019 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!