Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

appstract/laravel-referer-redirector

Repository files navigation

Laravel Referer Redirector

Latest Version on Packagist Total Downloads Software License Build Status

Manage redirects based on referers. You can add start and end dates so a referer can redirect to different url's in different time periods.

Installation

You can install the package via composer:

composer require appstract/laravel-referer-redirector

Publish

By running php artisan vendor:publish --provider="Appstract\RefererRedirector\RefererRedirectorServiceProvider" in your project all files for this package will be published. The file that will be published is a migration. A middleware will be registered.

Run the migration:

php artisan migrate

Usage

You need to add a middleware to handle the requests.

Add it to single routes:

Route::get('welcome', function () {
    //
})->middleware('redirect-referer');

Add it to route groups:

Route::group(['middleware' => ['redirect-referer']], function () {
    //
});

Or add it as global middleware:

protected $middleware = [
    ...

    \Appstract\RefererRedirector\Middleware\RedirectReferer::class,

    ...
];

Console

You can add a new redirect based on referer:

php artisan referer:make {referer} {redirect} {--start=} {--end=}

This will lead you through the needed steps.

Remove referer-redirect based on referer or ID:

php artisan referer:remove {referer}

List all referer-redirects:

php artisan referer:list

Notes

If you're going to add referer-redirects manually to the database, keep the following in mind:

  • referer_url: add without http://, https://, ending /
  • redirect_url: the package will make a redirect(redirect_url), so make sure this url exists
  • start_date: datetime (Carbon)
  • end_date: datetime (Carbon)

Testing

$ composer test

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.