Download the PHP package jcergolj/after-action-redirect-pagination-url-for-laravel without Composer
On this page you can find all versions of the php package jcergolj/after-action-redirect-pagination-url-for-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jcergolj/after-action-redirect-pagination-url-for-laravel
More information about jcergolj/after-action-redirect-pagination-url-for-laravel
Files in jcergolj/after-action-redirect-pagination-url-for-laravel
Package after-action-redirect-pagination-url-for-laravel
Short Description After CREATE, UPDATE or DELETE action paginated redirect url for laravel
License MIT
Informations about the package after-action-redirect-pagination-url-for-laravel
Why
The After Action Redirect Pagination URL for Laravel package provides a solution for two issues that developers may encounter when working with pagination in their Laravel application. These issues include redirected to an empty last page after deleting the last item on the last page.
Installation
Saving and Redirecting to Last Index URL with Query Parameters
This package allows you to save the full URL, including any query parameters, of the index page in the intended URL session. After a create or update action, you can use the to_intended_route
helper method to be redirected to the same page. You can also include or exclude routes from the intended URL saving mechanism for greater customization.
To use this feature, add the following code to your controller:
By default, to_intended_route
will redirect to the last intended URL. If no URL was intended, it will redirect to the users.index route.
Example:
Include and Exclude routes
To include or exclude routes from the intended URL saving mechanism, create a SetIntendedUrlMiddleware
class in the App\Http\Middleware namespace. In this class, you can specify the routes that should be excluded or included using the $excludedRoutes
and $includedRoutes
arrays.
Redirect to Last Page with Items after Deleting Last Item on Last Page
When you delete the last item on the last page of your Laravel app, you may encounter an issue where you are redirected to an empty last page. The After Action Redirect Pagination URL for Laravel package solves this problem by redirecting you to the last page with items.
To use this feature, add the following code after your paginated query:
This will check whether there are any items on the last page of your paginated results. If there are no items, it will redirect you to the last page that has items.
Here is an example of how you might use this in your controller's index method: