Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/Sevendays-Digital/twill-redirects
- Owner: Sevendays-Digital
- License: mit
- Created: 2022-03-17T11:11:54.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-07T12:26:42.000Z (about 1 year ago)
- Last Synced: 2024-08-03T17:12:38.855Z (5 months ago)
- Topics: twill, twill-package
- Language: PHP
- Homepage:
- Size: 84 KB
- Stars: 8
- Watchers: 0
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- awesome-twill - Twill Redirects - Manage redirects in Twill (Packages)
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 ?? '';
}
)
```