ilvalerione/laravel-https-redirect

Flexible https redirect for Laravel based applications

1.2.1 2019-10-29 08:06 UTC

This package is auto-updated.

Last update: 2024-10-29 05:17:00 UTC


README

Build Status Latest Stable Version License

Flexible https redirect for Laravel based applications

Install

composer require ilvalerione/laravel-https-redirect

Config

php artisan vendor:publish --provider="Aventure\HttpsRedirect\HttpsRedirectServiceProvider"

This command publish a new configuration file in your config directory to list all environment names that you want force to https:

return [
    'environments' => [
        // 'local', <-- usually no
        'development',
        'test',
        'production',
    ]
]

Or you can force all possible environment using wildcard:

return [
    'environments' => '*'
]

Use

Add HttpsMiddleware middleware in your global middleware section:

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $middleware = [
        ...,
        
        \Aventure\HttpsRedirect\Middleware\HttpsCheck::class,
    ];
    
    ...

Use as Route-Middleware

In alternative you can add middleware as named middleware in your Kernel file:

class Kernel extends HttpKernel
{
    /**
     * The application's global HTTP middleware stack.
     *
     * These middleware are run during every request to your application.
     *
     * @var array
     */
    protected $routeMiddleware  = [
        ...,
        
        'https_redirect' => \Aventure\HttpsRedirect\Middleware\HttpsCheck::class,
    ];
    
    ...

And use it programmatically in your routes configuration:

Route::middleware('https_redirect')->group(function(){

    Route::view('example', 'example');
    
});

LICENSE

This package are licensed under the MIT license.