Setting up laravel https request / secure http request / setting up ssl settings in laravel

  • Created: 28-06-2019
  • Posted By: Safina

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

1. Configure your web server to redirect all non-secure requests to https. Example of a nginx config:
server {

    listen 80 default_server;
    listen [::]:80 default_server;
    server_name example.com www.example.com;
    return 301 https://example.com$request_uri;
}

2. Set your environment variable APP_URL using https:
APP_URL=https://example.com

3. Use helper secure_url() (Laravel5.6)

4. Add following string to AppServiceProvider::boot() method (for version 5.4+):
\Illuminate\Support\Facades\URL::forceScheme('https');

5.Implicitly setting scheme for route group (Laravel5.6):
Route::group(['scheme' => 'https'], function () {
    // Route::get(...)->name(...);
});

6. Place this in the AppServiceProvider in the boot() method
if($this->app->environment('production')) {
    \URL::forceScheme('https');
}



Tags:

Post Comments