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

前端 未结 10 531
攒了一身酷
攒了一身酷 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:14

    I would prefer forceScheme instead of doing it on a web server. So Laravel app should be responsible for it.

    So right way is to add if statement inside boot function in your app/Providers/AppServiceProvider.php

        if (env('APP_ENV') === 'production') {
            \Illuminate\Support\Facades\URL::forceScheme('https');
        }
    

    Tip: to prove that you have APP_ENV configured correctly. Go to your Linux server, type env

    This was tested on Laravel 5, specifically 5.6.

提交回复
热议问题