Download the PHP package 1970mr/laravel-redirector without Composer
On this page you can find all versions of the php package 1970mr/laravel-redirector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 1970mr/laravel-redirector
More information about 1970mr/laravel-redirector
Files in 1970mr/laravel-redirector
Package laravel-redirector
Short Description A Laravel package for managing URL redirects easily and efficiently.
License MIT
Homepage https://github.com/1970Mr/laravel-redirector
Informations about the package laravel-redirector
Laravel Redirector
A Laravel package for managing URL redirects easily and efficiently.
Table of Contents
- Installation
- Configuration
- Usage
- Middleware
- Artisan Commands
- Controller and Views
- Custom Implementation
- Caching
- Testing
- License
Installation
You can install the package via Composer:
Next, you need to publish the migration and the config file:
Run the migrations to create the necessary database table:
Configuration
The package provides a configuration file where you can manage various settings, including caching methods and TTL (Time-To-Live). These settings allow you to optimize the performance and scalability of your redirects. Refer to the config/redirector.php
file for more details.
Usage
Middleware
To use the redirect middleware, you can apply it to specific routes, groups of routes, or add it globally to the HTTP kernel middleware stack.
Specific Routes
Global Middleware
In Laravel 11, you can add middleware globally in your bootstrap/app.php
file:
Alias Middleware
You can use the middleware by its alias or by the class name in your routes:
Artisan Commands
The package provides several Artisan commands to manage redirects:
Create Redirect
To create a redirect, you can use the redirect:create
Artisan command. This command allows you to specify the source URL, destination URL, status code, and whether the redirect is active.
Examples
-
Redirect from
/old-page
to/new-page
with a 301 status code and set it as active: - Redirect from
/specific-page
tohttps://google.com
with a 301 status code and set it as active:
Update Redirect
To update an existing redirect, you can use the redirect:update
Artisan command:
Example
Update the redirect from /old-page
to /new-destination
with a 302 status code and set it as active:
Delete Redirect
To delete a redirect, use the redirect:delete
Artisan command:
Example
Delete the redirect from /old-page
:
List Redirects
To list all configured redirects, use the redirect:list
Artisan command:
Controller and Views
You can also set up a more customizable CRUD interface for redirects using controllers, requests, routes, and views. The package provides a command to scaffold these components:
This command will install the necessary controllers, requests, routes, and views for managing redirects through a web interface.
Custom Implementation
Additionally, you can use the Redirect model directly to create, update, or delete redirects within your application code as needed. This approach allows for complete customization of how and where redirects are managed.
Caching
The package supports two caching methods:
- Full List: All active redirects are cached as a single collection. This method is efficient for a small number of redirects but may become inefficient as the number of redirects grows. Any create, update, or delete operation will reset the entire list cache.
- Single: Each redirect is cached individually. This method scales better with a large number of redirects but may result in more cache operations. Only the specific cached item is reset during create, update, or delete operations.
You can configure the caching method and TTL in the config/redirector.php
file to suit your application's needs.
Testing
To run the tests for the package, use the following command:
License
The MIT License (MIT). Please see License File for more information.