Skip to content

Instantly share code, notes, and snippets.

@mohamad-supangat
Last active February 7, 2024 09:26
Show Gist options
  • Save mohamad-supangat/270b0bc42a0870a828db6b61eb623417 to your computer and use it in GitHub Desktop.
Save mohamad-supangat/270b0bc42a0870a828db6b61eb623417 to your computer and use it in GitHub Desktop.
laravel force https in all routes

Place this in the AppServiceProvider in the boot() method

if($this->app->environment('production')) {
    \URL::forceScheme('https');
}
<?php

namespace App\Providers;

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

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     */
    public function register(): void
    {
        $this->app['request']->server->set('HTTPS', true);
    }

    /**
     * Bootstrap any application services.
     */
    public function boot(UrlGenerator $url): void
    {
        $url->forceScheme('https');
        // URL::forceScheme('https');
    }
}
@mohamad-supangat
Copy link
Author

fix livewire content mixed http and https

<?php
namespace App\Http\Middleware;
use Illuminate\Http\Request;
use Fideloper\Proxy\TrustProxies as Middleware;
class TrustProxies extends Middleware
{
    /**
     * The trusted proxies for this application.
     *
     * @var array|string
     */
    protected $proxies = '*';
    /**
     * The headers that should be used to detect proxies.
     *
     * @var int
     */
    protected $headers = Request::HEADER_X_FORWARDED_ALL;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment