How to force Laravel Project to use HTTPS for all routes?

前端 未结 10 539
攒了一身酷
攒了一身酷 2020-12-13 03:33

I am working on a project that requires a secure connection.

I can set the route, uri, asset to use \'https\' via:

Route::get(\'order/details/{id}\',         


        
10条回答
  •  生来不讨喜
    2020-12-13 04:13

    Force Https in Laravel 7.x (2020)


    "2020 Update? Url::forceScheme was acting funky for me, but this worked liked a dime."


    1. https code snippet.

      resolve(\Illuminate\Routing\UrlGenerator::class)->forceScheme('https');


    1. Add that snippet within any Service Provider Boot Method

    • 1: Open app/providers/RouteServiceProvider.php.
    • 2: Then add the https code snippet to the boot method.
        /**
         * Define your route model bindings, pattern filters, etc.
         *
         * @return void
         */
        public function boot()
        {
            resolve(\Illuminate\Routing\UrlGenerator::class)->forceScheme('https');
    
            parent::boot();
        }
    
    • 3: Lastly run php artisan route:clear && composer dumpautoload to clear Laravel's cached routes and cached Service Providers.

提交回复
热议问题