laravel InvalidArgumentException 路由 [登录] 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45906309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:33:25  来源:igfitidea点击:

InvalidArgumentException Route [login] not defined

phplaravelauthenticationroutes

提问by DevTaabi

enter image description here

在此处输入图片说明

I am unable to detect the problem. When I remove admin panel routes from the middle ware auth group it works really fine. But with that routes it through this exception.

我无法检测到问题。当我从中间件身份验证组中删除管理面板路由时,它工作得非常好。但是通过这个异常路由它。

Here is my routes file.

这是我的路由文件。

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


        Route::post('/signin','userController@postSignIn')->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);
        }
    }

These routes cause the problem . which are related to admin panel. I have the same user table for admins and users. When I remove admin panel routes from the group user can login perfectly. but when I add these routes user can't login nor the admin.

这些路由会导致问题。与管理面板相关。我为管理员和用户设置了相同的用户表。当我从组中删除管理面板路由时,用户可以完美登录。但是当我添加这些路由时,用户和管理员都无法登录。

    //admin-panel routes

Route::get('importExport', 'ExcelImportController@importExport');
Route::post('importExcel', 'ExcelImportController@importExcel');
Route::post('/logicsubmit','AdminController@logicsubmit')->name("logicsubmit");
Route::get('/RegularUser','AdminController@Regulars')->name("RegularUser");
Route::get('/Company','AdminController@Companies')->name("Company");
Route::post('/signup','userController@userSignUp')->name("signup");
Route::post('/companysignup','CompanyController@companySignUp')->name("companysignup");
Route::get('/logout','userController@logout')->name("logout");
Route::get('/dashboardd','AdminController@index')->name("dashboardd");
Route::get('/admit','AdminController@admit')->name("admit");
Route::get('/admin','AdminController@admin')->name("admin");
Route::get('/admins','AdminController@admins')->name("admins");

Route::get('/lock', 'AdminController@lock')->name("lock");
Route::post('/adminsignup','AdminController@AdminSignUp')->name("adminsignup");
Route::get('/view/{id}','AdminController@ViewUser')->name("view");
Route::get('/block/{id}','AdminController@blockUser')->name("block");
Route::get('/unblock/{id}','AdminController@unblockUser')->name("unblock");
Route::get('/delete/{id}','AdminController@deleteUser')->name("delete");
Route::get('/Addkeywords','AdminController@Addkeywords')->name("Addkeywords");
Route::post('/addword','AdminController@addword')->name("addword");
Route::get('/editword/{id}','AdminController@editword')->name("editword");
Route::get('/deleteword/{id}','AdminController@deleteword')->name("deleteword");
Route::post('/updateword/{id}','AdminController@updateword')->name("updateword");

//end of admin-panel routes

回答by DevK

You get this error because you're using route('login')somewhere in your code (probably a view) but you don't have a route with name login.

您收到此错误是因为您route('login')在代码中的某处使用(可能是视图),但您没有带有 name 的路由login

Renaming signinto loginwill probably do.

重命名signinlogin可能会做。

Route::post('/signin','userController@postSignIn')->name("login");

Or go through code and replace all calls to route route('login')to route('signin')

或者通过代码并替换所有调用以路由route('login')route('signin')

回答by Suniti Yadav

As you said when you remove auth middleware it works fine, the reason behind is 'auth' looking for authenticated routes that you can see by using php artisan route:listand if you use 'login' instead of '/signin' route it will work fine.So please rename your '/signin' route to auth's 'login', cause it is pre-defined.

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