Dynamic HTTPS assets Import with Laravel | Laravel SSL
If you are using Laravel with HTTPS and your website is not appearing as it should, possibly because the CSS and JS files aren't imported properly, you can follow this post to solve that.
In the .env file, we will create a new variable called REDIRECT_HTTPS
and set that to true when we are using HTTPS and false when we are not.
REDIRECT_HTTPS=true
Now, in app/Providers/AppServiceProviders.php
we will need to make a few changes. Make sure that your AppServiceProviders.php
looks similar to mine:
namespace App\Providers; use Illuminate\Routing\UrlGenerator; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { if(env('REDIRECT_HTTPS')) { $this->app['request']->server->set('HTTPS', true); } } /** * Bootstrap any application services. * * @return void */ public function boot(UrlGenerator $url) { if(env('REDIRECT_HTTPS')) { $url->formatScheme('https'); } } }