Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Sevendays-Digital/twill-redirects

Manage redirects in Twill
https://github.com/Sevendays-Digital/twill-redirects

twill twill-package

Last synced: about 1 month ago
JSON representation

Manage redirects in Twill

Awesome Lists containing this project

README

        

# Twill redirects

This package adds a redirects functionality to your Twill installation.

![screenshot](screenshot.png)

## Installation

Install it via composer:

```
composer require sevendays-digital/twill-redirects
```

(optional but required if redirecting to other modules) Then publish the config and set the modules inside:

```
php artisan vendor:publish --tag=twill-redirects-config
```

Finally run the migrations:

```
php artisan migrate
```

## Usage

You can now add redirects via the Twill backend.

Usage depends on your implementation. You can use the `RedirectManager` to figure it out:

```php
[
...
TwillRedirectMiddleware::class,
...
]
];
```

This will automatically take care of the redirect if there's a match.

But there is one exception, which is when you are using the `browser` to select the destination.

For that the package will not be able to return more than the slug out of the box, but you can manually intercept that
to handle the redirect.

In you `AppServiceProvider` you can add this to the `register` method:

```
// Example:
RedirectManager::onTwillEntityRedirect(
function(Model $model) {
if ($model instance ExampleModel) {
return route('my.route', ['id' => $model->id]);
}
return $model->slug ?? '';
}
)
```