How to change the path redirected by the auth middleware in Laravel 5.3?

1

using the php artisan method make: auth I run into the problem that once I use route protection doing

route::group(['prefix'=>'admin', 'middleware'=>'auth'], function(){...}

When I want to enter a protected route, it redirects me to / login but I have changed the route to login, so I get the error

  

NotFoundHttpException in RouteCollection.php line 161

Try to follow up with the Go to .. and get to the Authenticate class but there I stay and I can not find the redirect to login to change it

For what I read it is different from the others laravel 5. I guess I have to modify the handle () of RedirectIfAuthenticated

public function handle($request, Closure $next, $guard = null)
{
    if (Auth::guard($guard)->check()) {
        return redirect('/');
    }
        return $next($request);
}

probe returning a view if the check is false but no result

    
asked by Cidius 10.09.2016 в 00:24
source

1 answer

1

Considering that it is different in Laravel 5.3, now that route is modified in the ExceptionHandler :

app \ Exceptions \ Handler.php

/**
 * Convert an authentication exception into an unauthenticated response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Illuminate\Auth\AuthenticationException  $exception
 * @return \Illuminate\Http\Response
 */
protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    // ######### En esta línea cambias la ruta #########
    return redirect()->guest('login');
}
    
answered by 10.09.2016 / 00:29
source