Online Forum To Support Coders With Technical Assistance - Read Write Execute

Laravel : How to redirect back to previous page after login

Ankit Agrawal
Ankit Agrawal
Published on June 17, 2019 · 1 min read

laravel is free open source php framework.it is a very powerful tool to create large and robust web applications. It follows the MVC structure

Use below code to redirect back to previous page after login

Update your LoginController.php

use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\URL;

public function __construct()
{
    $this->middleware('guest', ['except' => 'logout']);
    Session::put('preUrl', URL::previous());
}


public function redirectTo()
{
    return Session::get('preUrl') ? Session::get('preUrl') :   $this->redirectTo;
}


Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article How to create a vendor list page in shopify Next Article → Return view as string in laravel