abu abu
abu abu

Reputation: 7028

Protecting Routes in Laravel 5.3

I am trying to protect my routes in Laravel 5.3. I am using below codes

Route::get('profile', function () {
    // Only authenticated users may enter...
})->middleware('auth');

If I try to browse /profile in logout situation it redirects me to /login route. But I would like to redirect it to / route.

How can I do that ??

Upvotes: 1

Views: 933

Answers (4)

Rashedul Islam Sagor
Rashedul Islam Sagor

Reputation: 2059

On laravel 5.3 it's on Exceptions directory. Go to App\Exceptions\Handler.php and on the bottom change the code:

    return redirect()->guest('/');

Upvotes: 1

Nesar
Nesar

Reputation: 21

You can try

Route::group(['middleware'=>'web'],function (){
Route::Auth();
Route::get('/home', 'HomeController@index');});

and change app\Middleware\RedirectIfAuthenticated.php

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

    return $next($request);
}

Upvotes: 0

Harsukh Makwana
Harsukh Makwana

Reputation: 4494

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

    return $next($request);
}

Please write this function in this file app\Middleware\RedirectIfAuthenticated.php

Upvotes: 0

Marcin
Marcin

Reputation: 1494

change file app\Middleware\RedirectIfAuthenticated.php

and edit this line:

return redirect('/login');

Upvotes: 1

Related Questions