InvalidArgumentException Route [登录]未定义

问题描述:

enter image description hereInvalidArgumentException Route [登录]未定义

我无法检测到问题。当我从中间件验证组中删除管理面板路线时,它的效果非常好。但是,通过这种路线,它通过这个例外。

这是我的路线文件。

Route::group(['middleware'=>['auth']],function(){ 


     Route::post('/signin','[email protected]')->name("signin"); 
    }); 

My controller function is : 

    public function postSignIn(Request $request) 
    { 
     $this->validate($request,[ 
      'email' => 'required|email', 
      'password' => 'required|min:6', 
     ]); 
     $email = $request['email']; 
     $user = User::where("email",$email)->first(); 

     if(Auth::attempt(['email' => $request['email'],'password' => $request['password']])) 
     { 
      if ($user['verified'] == 1){ 
       if ($user['role'] == 2) { 
        return redirect()->route('dashboardd'); 

       } 
       else if($user['role'] == 0 && $user['blocked'] == 1){ 
        $message = 'Your account has been blocked by admin'; 
        return redirect()->back()->with('message',$message); 

       }else if($user['role'] == 1 && $user['blocked'] == 1){ 
        $message = 'Your account has been blocked by admin'; 
        return redirect()->back()->with('message',$message); 
       } 
       else{ 
        return redirect()->route('news-feed'); 
//    return view('frontend.layouts.user_login_layout',compact('posts','comments','keywords','regular')); 
       } 
      } 
      else 
      { 
       $message = 'Account not verified! Verify Email to activate your account'; 
       return redirect()->route('home')->with('message',$message); 
      } 

     }else{ 
      $message = 'Wrong Credentials , Try Again ! '; 
      return redirect()->back()->with('message',$message); 
     } 
    } 

这些路线导致问题。这与管理面板有关。 我拥有管理员和用户的相同用户表。当我从组中删除管理面板路由时,用户可以完美登录。但是当我添加这些路线时,用户不能登录也不能管理员。

//admin-panel routes 

Route::get('importExport', '[email protected]'); 
Route::post('importExcel', '[email protected]'); 
Route::post('/logicsubmit','[email protected]')->name("logicsubmit"); 
Route::get('/RegularUser','[email protected]')->name("RegularUser"); 
Route::get('/Company','[email protected]')->name("Company"); 
Route::post('/signup','[email protected]')->name("signup"); 
Route::post('/companysignup','[email protected]')->name("companysignup"); 
Route::get('/logout','[email protected]')->name("logout"); 
Route::get('/dashboardd','[email protected]')->name("dashboardd"); 
Route::get('/admit','[email protected]')->name("admit"); 
Route::get('/admin','[email protected]')->name("admin"); 
Route::get('/admins','[email protected]')->name("admins"); 

Route::get('/lock', '[email protected]')->name("lock"); 
Route::post('/adminsignup','[email protected]')->name("adminsignup"); 
Route::get('/view/{id}','[email protected]')->name("view"); 
Route::get('/block/{id}','[email protected]')->name("block"); 
Route::get('/unblock/{id}','[email protected]')->name("unblock"); 
Route::get('/delete/{id}','[email protected]')->name("delete"); 
Route::get('/Addkeywords','[email protected]')->name("Addkeywords"); 
Route::post('/addword','[email protected]')->name("addword"); 
Route::get('/editword/{id}','[email protected]')->name("editword"); 
Route::get('/deleteword/{id}','[email protected]')->name("deleteword"); 
Route::post('/updateword/{id}','[email protected]')->name("updateword"); 

//end of admin-panel routes 
+0

你能后的堆栈跟踪?此外,突出部分是造成问题。(管理路线,因为你提到) – jaysingkar

+0

请阅读[在什么情况下我可以添加“紧急”或其他类似的短语到我的问题,以获得更快的答案? .*.com/q/326569) - 总结是,这不是解决志愿者问题的理想方式,而且可能会对获得答案产生反作用。请不要将这添加到您的问题。 – halfer

+0

@jaysingkar我更新了我提到的问题。 – DevTaabi

你得到这个错误是因为你在代码的某处使用route('login')(可能是一个视图),但是你没有一个名字为login的路由。

重命名signinlogin可能会做。

Route::post('/signin','[email protected]')->name("login"); 

或者办理代码并替换所有呼叫路由到route('login')route('signin')

+0

当我改变登录登录,它给RouteCollection-> methodNotAllowed(array('POST'))RouteCollection.php(行238) – DevTaabi

+0

这个错误MethodNotAllowedHttpException您需要用返回登录视图的'GET'路线替换这条路线。 – devk

+0

仍然存在问题未解决 – DevTaabi

就像你说的,当你删除身份验证的中间件,它工作正常,背后的原因是“权威性”而不是“/登入”寻找身份验证的路线,你可以通过使用php artisan route:list看,如果你用“登录”路由它将正常工作。所以请将您的'/ signin'路由重命名为auth的'login',因为它是预定义的。

+0

是的我使用登录路线而不是登录,但它工作正常时,我删除管理路线 – DevTaabi

+0

当你在内部登录它调用登录路由。所以你可以使用登录名来重命名它,或者你可以添加额外的路由为Route :: post('login','userController @ postSignIn'); –

+0

当我更改登录登录时,它在RouteCollection-> methodNotAllowed(array('POST'))给RouteCollection.php(第238行) 上的MethodNotAllowedHttpException(行238) – DevTaabi