PHP code example of asignua / filament-redirects

1. Go to this page and download the library: Download asignua/filament-redirects library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asignua / filament-redirects example snippets


use Asignua\FilamentRedirects\RedirectsPlugin;

$panel->plugin(RedirectsPlugin::make()
    ->authorize(fn (): bool => auth()->user()?->isAdmin()));

use Asignua\FilamentRedirects\Redirects;
use Illuminate\Foundation\Configuration\Middleware;

->withMiddleware(function (Middleware $middleware): void {
    Redirects::appendTo($middleware);
})

Route::middleware(['web', ...Redirects::middleware()])
    ->get('/{path?}', FrontController::class)
    ->where('path', '.*');

'ignore' => ['wp-*', '*/wp-*', '*.php', '.env*', '.git/*', '*.png', '*.map', /* ... */], // wildcards, case-insensitive
'ignore_user_agents' => ['*semrushbot*'],
'ignore_bots' => false, // off on purpose: a Googlebot request for a dead URL is what you want to see

Redirects::locales(default: 'uk', all: ['uk', 'en', 'de'], unprefixed: 'uk');
// /about -> uk, /en/about -> en, /de/about -> de

use Asignua\FilamentRedirects\Enums\RedirectCode;
use Asignua\FilamentRedirects\Redirects;

Redirects::create('old/page', 'new/page');                                   // 301, default language
Redirects::create('old/page', 'new/page', 302, 'en');                        // 302 for the `en` row
Redirects::create('old/page', 'https://other.site/x', RedirectCode::PermanentKeepMethod);
Redirects::create('retired', '', RedirectCode::Gone);                        // answer with the error page (410)
Redirects::create('old/page', 'new/page', entity: $post);                    // remember what it leads to

RedirectsPlugin::make()
    ->authorize(fn (): bool => auth()->user()?->isAdmin())
    ->navigationGroup('SEO')
    ->navigationSort(30)
    ->navigationIcon('heroicon-o-arrows-right-left')
    ->redirects()        // or ->redirects(false) to hide the resource
    ->notFoundLog();     // or ->notFoundLog(false)
bash
composer vendor:publish --tag=filament-redirects-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=filament-redirects-config
bash
php artisan vendor:publish --tag=filament-redirects-translations