Laravel 5.4 Route [login] not defined











up vote
0
down vote

favorite












Hi I have following route and constructor in my controller i want to check if user is authenticated or not if not then redirect to /warehouse/login page. but for some reasons i am getting Route [login] not defined error.



I am migrating my functions from Laravel 4.2 to Laravel 5.4



Constructor:



public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if (!Auth::check()) {
$url = URL::current();
$routeName = Route::currentRouteName();

if ($routeName != "AdminLogin" && $routeName != 'admin') {
Session::put('pre_admin_login_url', $url);
}
return redirect('/warehouse/login');
}

return $next($request);

}, array('except' => array('WarehouseAdminLogin', 'WarehouseAdminVerify')));


}


Routes:



Route::get('/warehouse', 'WarehouseController@index');
Route::get('/warehouse/login', array('as' => 'WarehouseAdminLogin', 'uses' => 'WarehouseController@login'));









share|improve this question
























  • Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
    – nakov
    Nov 7 at 9:03










  • @nakov if i remove that then getting the page isn't redirecting properly error.
    – Danish Jamshed
    Nov 7 at 9:05










  • so as I said, it is because you are missing the routes in your route file.
    – nakov
    Nov 7 at 9:08










  • @nakov can you please write here which route i am missing ?
    – Danish Jamshed
    Nov 7 at 9:13










  • Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
    – nakov
    Nov 7 at 9:18















up vote
0
down vote

favorite












Hi I have following route and constructor in my controller i want to check if user is authenticated or not if not then redirect to /warehouse/login page. but for some reasons i am getting Route [login] not defined error.



I am migrating my functions from Laravel 4.2 to Laravel 5.4



Constructor:



public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if (!Auth::check()) {
$url = URL::current();
$routeName = Route::currentRouteName();

if ($routeName != "AdminLogin" && $routeName != 'admin') {
Session::put('pre_admin_login_url', $url);
}
return redirect('/warehouse/login');
}

return $next($request);

}, array('except' => array('WarehouseAdminLogin', 'WarehouseAdminVerify')));


}


Routes:



Route::get('/warehouse', 'WarehouseController@index');
Route::get('/warehouse/login', array('as' => 'WarehouseAdminLogin', 'uses' => 'WarehouseController@login'));









share|improve this question
























  • Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
    – nakov
    Nov 7 at 9:03










  • @nakov if i remove that then getting the page isn't redirecting properly error.
    – Danish Jamshed
    Nov 7 at 9:05










  • so as I said, it is because you are missing the routes in your route file.
    – nakov
    Nov 7 at 9:08










  • @nakov can you please write here which route i am missing ?
    – Danish Jamshed
    Nov 7 at 9:13










  • Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
    – nakov
    Nov 7 at 9:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Hi I have following route and constructor in my controller i want to check if user is authenticated or not if not then redirect to /warehouse/login page. but for some reasons i am getting Route [login] not defined error.



I am migrating my functions from Laravel 4.2 to Laravel 5.4



Constructor:



public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if (!Auth::check()) {
$url = URL::current();
$routeName = Route::currentRouteName();

if ($routeName != "AdminLogin" && $routeName != 'admin') {
Session::put('pre_admin_login_url', $url);
}
return redirect('/warehouse/login');
}

return $next($request);

}, array('except' => array('WarehouseAdminLogin', 'WarehouseAdminVerify')));


}


Routes:



Route::get('/warehouse', 'WarehouseController@index');
Route::get('/warehouse/login', array('as' => 'WarehouseAdminLogin', 'uses' => 'WarehouseController@login'));









share|improve this question















Hi I have following route and constructor in my controller i want to check if user is authenticated or not if not then redirect to /warehouse/login page. but for some reasons i am getting Route [login] not defined error.



I am migrating my functions from Laravel 4.2 to Laravel 5.4



Constructor:



public function __construct()
{
$this->middleware('auth');
$this->middleware(function ($request, $next) {
if (!Auth::check()) {
$url = URL::current();
$routeName = Route::currentRouteName();

if ($routeName != "AdminLogin" && $routeName != 'admin') {
Session::put('pre_admin_login_url', $url);
}
return redirect('/warehouse/login');
}

return $next($request);

}, array('except' => array('WarehouseAdminLogin', 'WarehouseAdminVerify')));


}


Routes:



Route::get('/warehouse', 'WarehouseController@index');
Route::get('/warehouse/login', array('as' => 'WarehouseAdminLogin', 'uses' => 'WarehouseController@login'));






laravel laravel-5 laravel-5.4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 7 at 9:03

























asked Nov 7 at 8:59









Danish Jamshed

15




15












  • Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
    – nakov
    Nov 7 at 9:03










  • @nakov if i remove that then getting the page isn't redirecting properly error.
    – Danish Jamshed
    Nov 7 at 9:05










  • so as I said, it is because you are missing the routes in your route file.
    – nakov
    Nov 7 at 9:08










  • @nakov can you please write here which route i am missing ?
    – Danish Jamshed
    Nov 7 at 9:13










  • Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
    – nakov
    Nov 7 at 9:18


















  • Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
    – nakov
    Nov 7 at 9:03










  • @nakov if i remove that then getting the page isn't redirecting properly error.
    – Danish Jamshed
    Nov 7 at 9:05










  • so as I said, it is because you are missing the routes in your route file.
    – nakov
    Nov 7 at 9:08










  • @nakov can you please write here which route i am missing ?
    – Danish Jamshed
    Nov 7 at 9:13










  • Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
    – nakov
    Nov 7 at 9:18
















Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
– nakov
Nov 7 at 9:03




Your error comes from within $this->middleware('auth'); I guess you don't have Auth::routes(); within your routes file.
– nakov
Nov 7 at 9:03












@nakov if i remove that then getting the page isn't redirecting properly error.
– Danish Jamshed
Nov 7 at 9:05




@nakov if i remove that then getting the page isn't redirecting properly error.
– Danish Jamshed
Nov 7 at 9:05












so as I said, it is because you are missing the routes in your route file.
– nakov
Nov 7 at 9:08




so as I said, it is because you are missing the routes in your route file.
– nakov
Nov 7 at 9:08












@nakov can you please write here which route i am missing ?
– Danish Jamshed
Nov 7 at 9:13




@nakov can you please write here which route i am missing ?
– Danish Jamshed
Nov 7 at 9:13












Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
– nakov
Nov 7 at 9:18




Auth::routes(); in your routes file. This defines those login, register and so on routes which are used within the Auth middleware.
– nakov
Nov 7 at 9:18












2 Answers
2






active

oldest

votes

















up vote
0
down vote













You didnt define your login function.



make a function
public function login()
{'your code'}



in your WarehouseController






share|improve this answer





















  • I have a login function in WarehouseController.
    – Danish Jamshed
    Nov 7 at 9:51










  • ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
    – Moubarak Hayal
    Nov 7 at 10:07


















up vote
0
down vote













Edited: the problem is that you have not a route named login. This error is caused by:



$this->middleware('auth');


because this code in the auth middleware:



protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}


So what to do is remove auth middleware and try again or make a route with login name.






share|improve this answer























  • try this @danishjamshed
    – Mahdi Jedari
    Nov 7 at 10:59










  • I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
    – Danish Jamshed
    Nov 7 at 11:32










  • keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
    – Mahdi Jedari
    Nov 7 at 11:37












  • this is working login page is showing but now when i enter username password its redirecting me back to login page.
    – Danish Jamshed
    Nov 7 at 12:15










  • Login form is submitting to verify function
    – Danish Jamshed
    Nov 7 at 12:17











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186216%2flaravel-5-4-route-login-not-defined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













You didnt define your login function.



make a function
public function login()
{'your code'}



in your WarehouseController






share|improve this answer





















  • I have a login function in WarehouseController.
    – Danish Jamshed
    Nov 7 at 9:51










  • ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
    – Moubarak Hayal
    Nov 7 at 10:07















up vote
0
down vote













You didnt define your login function.



make a function
public function login()
{'your code'}



in your WarehouseController






share|improve this answer





















  • I have a login function in WarehouseController.
    – Danish Jamshed
    Nov 7 at 9:51










  • ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
    – Moubarak Hayal
    Nov 7 at 10:07













up vote
0
down vote










up vote
0
down vote









You didnt define your login function.



make a function
public function login()
{'your code'}



in your WarehouseController






share|improve this answer












You didnt define your login function.



make a function
public function login()
{'your code'}



in your WarehouseController







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 9:48









Moubarak Hayal

395




395












  • I have a login function in WarehouseController.
    – Danish Jamshed
    Nov 7 at 9:51










  • ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
    – Moubarak Hayal
    Nov 7 at 10:07


















  • I have a login function in WarehouseController.
    – Danish Jamshed
    Nov 7 at 9:51










  • ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
    – Moubarak Hayal
    Nov 7 at 10:07
















I have a login function in WarehouseController.
– Danish Jamshed
Nov 7 at 9:51




I have a login function in WarehouseController.
– Danish Jamshed
Nov 7 at 9:51












ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
– Moubarak Hayal
Nov 7 at 10:07




ok, I didnt see that in your code, then you need to check if you have Auth::routes(); in your web.php. And login is route::post not get. Goodluck :)
– Moubarak Hayal
Nov 7 at 10:07












up vote
0
down vote













Edited: the problem is that you have not a route named login. This error is caused by:



$this->middleware('auth');


because this code in the auth middleware:



protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}


So what to do is remove auth middleware and try again or make a route with login name.






share|improve this answer























  • try this @danishjamshed
    – Mahdi Jedari
    Nov 7 at 10:59










  • I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
    – Danish Jamshed
    Nov 7 at 11:32










  • keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
    – Mahdi Jedari
    Nov 7 at 11:37












  • this is working login page is showing but now when i enter username password its redirecting me back to login page.
    – Danish Jamshed
    Nov 7 at 12:15










  • Login form is submitting to verify function
    – Danish Jamshed
    Nov 7 at 12:17















up vote
0
down vote













Edited: the problem is that you have not a route named login. This error is caused by:



$this->middleware('auth');


because this code in the auth middleware:



protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}


So what to do is remove auth middleware and try again or make a route with login name.






share|improve this answer























  • try this @danishjamshed
    – Mahdi Jedari
    Nov 7 at 10:59










  • I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
    – Danish Jamshed
    Nov 7 at 11:32










  • keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
    – Mahdi Jedari
    Nov 7 at 11:37












  • this is working login page is showing but now when i enter username password its redirecting me back to login page.
    – Danish Jamshed
    Nov 7 at 12:15










  • Login form is submitting to verify function
    – Danish Jamshed
    Nov 7 at 12:17













up vote
0
down vote










up vote
0
down vote









Edited: the problem is that you have not a route named login. This error is caused by:



$this->middleware('auth');


because this code in the auth middleware:



protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}


So what to do is remove auth middleware and try again or make a route with login name.






share|improve this answer














Edited: the problem is that you have not a route named login. This error is caused by:



$this->middleware('auth');


because this code in the auth middleware:



protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}


So what to do is remove auth middleware and try again or make a route with login name.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 7 at 10:39

























answered Nov 7 at 9:41









Mahdi Jedari

828




828












  • try this @danishjamshed
    – Mahdi Jedari
    Nov 7 at 10:59










  • I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
    – Danish Jamshed
    Nov 7 at 11:32










  • keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
    – Mahdi Jedari
    Nov 7 at 11:37












  • this is working login page is showing but now when i enter username password its redirecting me back to login page.
    – Danish Jamshed
    Nov 7 at 12:15










  • Login form is submitting to verify function
    – Danish Jamshed
    Nov 7 at 12:17


















  • try this @danishjamshed
    – Mahdi Jedari
    Nov 7 at 10:59










  • I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
    – Danish Jamshed
    Nov 7 at 11:32










  • keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
    – Mahdi Jedari
    Nov 7 at 11:37












  • this is working login page is showing but now when i enter username password its redirecting me back to login page.
    – Danish Jamshed
    Nov 7 at 12:15










  • Login form is submitting to verify function
    – Danish Jamshed
    Nov 7 at 12:17
















try this @danishjamshed
– Mahdi Jedari
Nov 7 at 10:59




try this @danishjamshed
– Mahdi Jedari
Nov 7 at 10:59












I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
– Danish Jamshed
Nov 7 at 11:32




I tried removing $this->middleware('auth'); but now getting the page is not redirecting properly error @Mahdi
– Danish Jamshed
Nov 7 at 11:32












keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
– Mahdi Jedari
Nov 7 at 11:37






keep the middleware and just change the name of WarehouseAdminLogin route to login @DanishJamshed
– Mahdi Jedari
Nov 7 at 11:37














this is working login page is showing but now when i enter username password its redirecting me back to login page.
– Danish Jamshed
Nov 7 at 12:15




this is working login page is showing but now when i enter username password its redirecting me back to login page.
– Danish Jamshed
Nov 7 at 12:15












Login form is submitting to verify function
– Danish Jamshed
Nov 7 at 12:17




Login form is submitting to verify function
– Danish Jamshed
Nov 7 at 12:17


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186216%2flaravel-5-4-route-login-not-defined%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini