- Make sure you're using this properly. Do at your own risk!
- Add this service provider to your app
- Adjust configuration in
config/app.php
like this:return [ 'https' => env('HTTPS', false), 'providers' => [ // Application Service Providers... App\Providers\ForceHttpsServiceProvider::class, ] ];
Created
July 22, 2020 23:49
-
-
Save zhanang19/fd6a0f09531cc560f051171ff49035b5 to your computer and use it in GitHub Desktop.
Force url generator in Laravel to use HTTPS scheme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Routing\UrlGenerator; | |
use Illuminate\Support\ServiceProvider; | |
class ForceHttpsServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register any application services. | |
*/ | |
public function register() | |
{ | |
// | |
} | |
/** | |
* Bootstrap any application services. | |
*/ | |
public function boot(UrlGenerator $url) | |
{ | |
if (config('app.https')) { | |
$url->forceScheme('https'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment