Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}', ['uses' => 'OrderController@details', 'as' => 'order.details', 'https']);  url($language.'/index', [], true)  asset('css/bootstrap.min.css', true) 

But setting the parameters all the time seems tiring.

Is there a way to force all routes to generate HTTPS links?

like image 643
Nelson Melecio Avatar asked Mar 06 '16 12:03

Nelson Melecio


People also ask

How do I get http or HTTPS in laravel?

Laravel Forge automatically redirects HTTP to HTTPS when you activate the SSL certificate. This is done by nginx that handles the certificate on your server, this also includes the traffic that's not being served by your Laravel application (for example static files, like /js/app.

What middleware can be specified to redirect all HTTP requests to HTTPS?

HTTPS Redirection Middleware (UseHttpsRedirection) to redirect HTTP requests to HTTPS.


1 Answers

Place this in the AppServiceProvider in the boot() method

if($this->app->environment('production')) {     \URL::forceScheme('https'); } 
like image 82
Amitesh Bharti Avatar answered Oct 10 '22 08:10

Amitesh Bharti