The Laravel UrlGenerator has a method called forceSchema that allows you to force the use of the scheme and ignore the request from the URL. Just create a service provider, SecureRoutingServiceProvider , that uses the Laravel IOC to override the default generator and returns an instance that forces a secure scheme:
use Illuminate\Routing\UrlGenerator; use Illuminate\Routing\RoutingServiceProvider; class SecureRoutingServiceProvider extends RoutingServiceProvider { public function boot() { App::bind('url', function () { $generator = new UrlGenerator( App::make('router')->getRoutes(), App::make('request'); }); $generator->forceSchema('https'); return $generator; } parent::boot(); } }
Next, we need to register the service provider by adding it to the providers array in app/config/app.php :
'providers' => array( ..., 'SecureRoutingServiceProvider', )
And all this to him. I tested this code and it works fine (in Laravel 4.2).
source share