How to Load Blade assets with https in Laravel in production?

Here are the steps you can follow to configure your Laravel application to use HTTPS in production:

  1. Make sure that your web server is configured to support HTTPS. This typically involves installing an SSL certificate on your web server and configuring it to use HTTPS.

  2. Update the APP_URL variable in your .env file to use HTTPS. For example:


APP_URL=https://example.com
  1. Make sure that the forceScheme method is set to 'https' in the AppServiceProvider. This will ensure that Laravel generates HTTPS URLs for all links and assets in your application. Here's an example:

use Illuminate\Support\Facades\URL;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if (config('app.env') === 'production') {
            URL::forceScheme('https');
        }
    }
}

With these steps in place, your Laravel application will be configured to use HTTPS and will generate HTTPS URLs for all links and assets, including those in your Blade templates.

Comments

Leave a Reply