1

Route [login] not defined. C:\xampp\xampp\htdocs\MMICTLTD\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php Guys I need your help, I keep getting this error of route login not defined, am running laravel 5.6 Am trying to setup multiple authentication but this error is having me so frustrated. Any help

My handler.php

<?php

namespace App\Exceptions;

use Exception;
    use Request;
    use Illuminate\Auth\AuthenticationException;
    use Response;
    use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var array
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var array
     */
    protected $dontFlash = [
        'password',
        'password_confirmation',
    ];

    /**
     * Report or log an exception.
     *
     * @param  \Exception  $exception
     * @return void
     */
    public function report(Exception $exception)
    {
        parent::report($exception);
    }

    /**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $exception
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $exception)
    {
        return parent::render($request, $exception);
    }
         protected function unauthenticated($request, AuthenticationException $exception)
         {
          if ($request->expectsJson()) {
            // code...
            return response()->json(['error' => 'unauthenticated.'], 401);
          }

          $guard = array_get($exception->guards(), 0);

          switch ($guard) {
            case 'admin':
              $login = 'admin.login';
              break;

            default:
                return redirect()->guest(route('login'));
              break;
          }

    }
}

My Routes

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/',[
    'uses' => 'ShopController@getHome',
    'as' => 'layouts.master',
]);

Route::get('/shop',[
    'uses' => 'ShopController@getIndex',
    'as' => 'pages.shop',
]);
Route::get('/blog',[
    'uses' => 'ShopController@getblog',
    'as' => 'pages.blog',
]);
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');

Route::GET('admin/home','AdminController@index');       

Route::GET('login','Admin\LoginController@showLoginForm')->name('admin.login');
Route::POST('login','Admin\LoginController@login');                  
Route::POST('admin-password/email','Admin\ForgotPasswordController@sendResetLinkEmail')->name('admin.password.email'); 
Route::GET('admin-password/reset', 'Admin\ForgotPasswordController@showLinkRequestForm')->name('admin.password.request');
Route::POST('admin-password/reset','Admin\ResetPasswordController@reset'); 
Route::GET('admin-password/reset/{token}', 'Admin\ResetPasswordController@showResetForm')->name('admin.password.reset');

2 Answers2

1

You named route as admin.login. Use

return redirect()->guest(route('admin.login'));

Instead

return redirect()->guest(route('login'));
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
  • Alos your routes are overwritten with `Auth::routes()` , [Check here](https://stackoverflow.com/a/49870403/2815635) – Niklesh Raut Aug 22 '18 at 11:42
0

Move this line

Route::GET('login','Admin\LoginController@showLoginForm')->name('admin.login');

above this line

Auth::routes();

SO it will look like this :

 Route::GET('login','Admin\LoginController@showLoginForm')->name('admin.login');
 Auth::routes();

And use this line for redirect

return redirect()->guest(route('admin.login'));

I hove it might help you.

narayansharma91
  • 2,273
  • 1
  • 12
  • 20