Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel form HTTPS action

Tags:

php

https

laravel

I'm using Laravel in an application that I would like to be HTTPS-only.

In one view that is shown on https://example.com/p I open a form like this:

{{ Form::open(['method' => "POST", "id" => "whatever"]) }}

Laravel parses it to this:

<form method="POST" action="http://example.com/p" accept-charset="UTF-8" id="whatever">

This looks good on the first sight, but remember, this is on an HTTPS page so I get a mixed-content warning when displaying the page.

But it gets even worse. I configured my server to redirect HTTP request to the according HTTPS resource. That means, my browser posts the form content to the server, which redirects it to the HTTPS-location. The browser then drops the POST-request and sends a regular GET-request to the server which results in exactly the same page the use has seen before.

Why does Laravel fill in the wrong protocol? How can I set the right one?

like image 403
Johann Bauer Avatar asked Nov 29 '25 13:11

Johann Bauer


1 Answers

Define your routes with https option and call that route to form action. For Example"

Route

Route::group(array('https'), function(){
    // all of our routes
    //for your form acction
    Route::post('form', array('as' => 'form/action', 'uses' => 'ExampleController@postForm'));  
}

So the route under https group should be https, even route for form to.

like image 130
Safoor Safdar Avatar answered Dec 01 '25 02:12

Safoor Safdar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!