Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto secure form on Laravel 4.2

I'm using Laravel 4.2 and everything looks fine. But I have a problem with the SSL when I use Form::open() Function. It always using HTTP without SSL even when the site is using SSL.

I saw this question: Laravel: HTTPS in Form::open() But there's 2 problems with that: I need to do it manually for each form. and when I program on my Wamp Server, I have HTTP so it won't work on my localhost.

So my question is, How can I auto secure the form if the site is using SSL?

like image 269
Eliya Cohen Avatar asked Jul 08 '15 12:07

Eliya Cohen


2 Answers

You can create a route group with the https option, and insert all of your routes inside that group.

Example:

Route::group(array('https'), function(){
    // All routes goes here
});

Then your forms should be https.

Another solution may be just:

URL::forceSchema("https");
like image 84
HTMHell Avatar answered Nov 03 '22 17:11

HTMHell


You can use Request::secure() to check if the request is over HTTPS and use the return value in the URL helper like this:

Form::open(array('url' => URL::to('/', array(), Request::secure())))

This way you form should automatically use HTTP or HTTPS depending if the current request is using HTTPS or not.

like image 20
Needpoule Avatar answered Nov 03 '22 15:11

Needpoule