PHP code example of esign / laravel-redirects

1. Go to this page and download the library: Download esign/laravel-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/ */

    

esign / laravel-redirects example snippets


// bootstrap/app.php

->withMiddleware(function (Middleware $middleware) {
     $middleware->append(Esign\Redirects\Http\Middleware\CheckForRedirects::class);
})

// app/Http/Kernel.php

protected $middleware = [
    ...
    Esign\Redirects\Http\Middleware\CheckForRedirects::class,
];

return [
    /**
     * This is the model used by the DatabaseRedirector.
     * It should implement the RedirectContract interface and extend the Model class.
     */
    'redirect_model' => Esign\Redirects\Models\Redirect::class,

    /**
     * This class provides the redicect url's to the CheckForRedirects middleware.
     * It should implement the RedirectorContract interface.
     */
    'redirector' => Esign\Redirects\Redirectors\DatabaseRedirector::class,

    'cache' => [
        /**
         * The key that will be used to cache the redirects.
         */
        'key' => 'esign.laravel-redirects.redirects',

        /**
         * The duration for which database redirects will be cached.
         */
        'ttl' => \DateInterval::createFromDateString('24 hours'),

        /**
         * The cache store to be used for database redirects.
         * Use null to utilize the default cache store from the cache.php config file.
         * To disable caching, you can use the 'array' store.
         */
        'store' => null,
    ],
];

Redirect::create([
    'old_url' => 'my-old-url',
    'new_url' => 'my-new-url',
]);

Redirect::create([
    'old_url' => 'my-old-url/{slug}',
    'new_url' => 'my-new-url/{slug}',
]);

Redirect::create([
    'old_url' => 'my-old-url/{slug}/{year}',
    'new_url' => 'my-new-url/{year}/{slug}',
]);

Redirect::create([
    'old_url' => 'my-old-url/{slug}/{year}',
    'new_url' => 'my-new-url/{year}/{slug}',
    'status_code' => 301,
]);

Redirect::create([
    'old_url' => 'my-old-url',
    'new_url' => 'https://www.esign.eu',
]);

Redirect::create([
    'old_url' => 'user/{id}',
    'new_url' => 'users/{id}',
    'constraints' => ['id' => '[0-9]+'],
]);

Redirect::create([
    'old_url' => 'nl/{any?}',
    'new_url' => 'nl-be/{any?}',
    'constraints' => ['any' => '.*'],
]);

Redirect::create([
    'old_url' => 'my-old-url/*',
    'new_url' => 'my-new-url/*',
]);
bash
php artisan vendor:publish --provider="Esign\Redirects\RedirectsServiceProvider" --tag="migrations"
bash
php artisan vendor:publish --provider="Esign\Redirects\RedirectsServiceProvider" --tag="config"
bash
php artisan redirects:clear-cache