cwsdigital/twill-redirects

Add an simple redirect capsule to your Twill projects.

1.1 2023-11-03 09:49 UTC

This package is auto-updated.

Last update: 2024-11-03 11:52:54 UTC


README

Latest Version on Packagist MIT Licensed Total Downloads

Add new redirect module preview

What it does

This package provides a simple way to allow users to manage any Redirects for their Twill Sites.

Requirements

This package requires Laravel 8 or higher, PHP8 or higher, and Twill 3.0 or higher.

Installation

First you want to install this dependency using composer, you can do this by running the following command:

$ composer require cwsdigital/twill-redirects
$ php artisan migrate

Configuration

Adding to your Twill Admin

This package is set up to automatically register the Redirects Capsule and add it directly to the Twill Admin Navigation.

Twill Admin Menu

You may want to determine where to place the Redirects module in your Twill Navigation, for example, you want Redirects to appear as a secondary menu item within a primary navigation of Settings.

First you will need to publish the config file:

  php artisan vendor:publish --provider="CwsDigital\TwillRedirects\TwillRedirectsServiceProvider" --tag=config

Secondly, change the 'automaticNavigation' to false. This will prevent Twill from automatically adding the Redirects Primary Navigation link.

TwillNavigation::addLink(
    NavigationLink::make()->title('Settings')
        ->forModule('redirects')
    ->doNotAddSelfAsFirstChild()
    ->setChildren([
        NavigationLink::make()->title('Redirects')->forModule('redirects'),
    ])
);

Adding to your frontend Middleware

To make your frontend routing aware of the Redirect middleware you need to add this to the laravel middleware in Kernel.php

{{-- app/Http/Kernel.php --}}

protected $middleware = [
    // Add HandlesPageRedirects::class
    CwsDigital\TwillRedirects\Twill\Capsules\Redirects\Http\Middleware\HandlesPageRedirects::class,
];

Events

There are two events triggered in the Redirect Middleware.

  1. RedirectWasFound event is triggered when a redirect has been found.
  2. RedirectWasNotFound event is triggered when no redirect was found.

Changelog

Please see CHANGELOG for details.

License

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