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'));
laravel laravel-5 laravel-5.4
|
show 1 more comment
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'));
laravel laravel-5 laravel-5.4
Your error comes from within$this->middleware('auth');
I guess you don't haveAuth::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 thoselogin
,register
and so on routes which are used within theAuth
middleware.
– nakov
Nov 7 at 9:18
|
show 1 more comment
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'));
laravel laravel-5 laravel-5.4
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
laravel laravel-5 laravel-5.4
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 haveAuth::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 thoselogin
,register
and so on routes which are used within theAuth
middleware.
– nakov
Nov 7 at 9:18
|
show 1 more comment
Your error comes from within$this->middleware('auth');
I guess you don't haveAuth::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 thoselogin
,register
and so on routes which are used within theAuth
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
|
show 1 more comment
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
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
add a comment |
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.
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
add a comment |
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
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
add a comment |
up vote
0
down vote
You didnt define your login function.
make a function
public function login()
{'your code'}
in your WarehouseController
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
add a comment |
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
You didnt define your login function.
make a function
public function login()
{'your code'}
in your WarehouseController
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Your error comes from within
$this->middleware('auth');
I guess you don't haveAuth::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 thoselogin
,register
and so on routes which are used within theAuth
middleware.– nakov
Nov 7 at 9:18