2

I'm create a web using laravel on a https website example: https://examples.com. And I have a blade view which has a form with action to another page https://examples.com/next I used this in my blade file: <form action="{{url("next")}}" method="POST" id="page">.

But when I test on browser, it show an warning like: Mixed Content: The page at 'https://examples.com' was loaded over a secure connection, but contains a form that targets an insecure endpoint 'http://examples.com/next'. This endpoint should be made available over a secure connection.

When I inspect <form>, it show <form action="http://examples.com/next" method="POST" id="page">

Anyone has idea about this? Thanks

1 Answer 1

7

url() helper in laravel uses automatically http/https depending on the protocol of the request. If the page is https://examples.com it should generate https links.

If there is a proxy in place that switchs protocol, that error might happen. In that case you have two choices.

A local solution

<form action="{{secure_url("next")}}" method="POST" id="page"> 

a global solution

//in app\Providers\AppServiceProvider.php class AppServiceProvider extends ServiceProvider { public function boot(UrlGenerator $url) { if (env('APP_ENV') !== 'local') { //so you can work on it locally $url->forceScheme('https'); } } //... } 
Sign up to request clarification or add additional context in comments.

2 Comments

Does it not look for the app url in the .env file?
@user3532758 The APP_URL in the .env file is used when generating urls with CLI, in request mode (fpm) it will uses $_SERVER variables and generate the link from it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.