maxweb/save-url

Laravel 5 package to redirect users to the last visited page on login.

v1.0.4 2017-09-04 10:05 UTC

This package is auto-updated.

Last update: 2024-11-16 00:43:48 UTC


README

Introduction

This package allows you to easily redirect users to the last visited page on login.

Laravel compatibility

Installation

Require through composer

composer require maxweb/save-url 1.0.x

Or manually edit your composer.json file:

"require": {
	"maxweb/save-url": "1.0.x"
}

Publish the configuration file:

php artisan vendor:publish

This package supports Laravel 5.5's automatic package discovery feature, so there is no need to add anything to config/app.php in Laravel 5.5 and above.

Usage

Cached urls

By default, the last visited URL visited by a user is saved in Session. URLs must follow these criteria to be saved:

- Only GET requests are saved.
- AJAX requests are not saved.
- If the user is logged in, no urls are saved.

Excluding urls from the cache

If you want to exclude certain urls from the url cache, like for example the login and signup pages, you may use the provided "doNotSave" middleware:

// routes/web.php

Route::get('/login', ['middleware' => 'doNotSave', 'uses' => 'AuthController@login']);

Redirecting after login

To redirect the user to the last saved url, such as after authentication, you may use:

public function login() {
	/** Auth user **/
	if ($success) {
		redirect()->toSavedUrl();
	}
}