Auto Secure Form on Laravel 4.2

I am using Laravel 4.2 and everything looks great. But I have a problem with SSL when I use Form::open() Function. It always uses HTTP without SSL, even when the site uses SSL.

I saw this question: Laravel: HTTPS in the form :: open () But there are two problems with this: I need to do this manually for each form. and when I program on my Wamp Server, I have HTTP, so it won’t work on my local host.

So my question is: how can I automatically protect the form if the site uses SSL?

+6
source share
2 answers

You can create a route group with the https option and insert all your routes within this group.

Example:

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

Then your forms should be https .

Another solution might be simple:

 URL::forceSchema("https"); 
+4
source

You can use Request::secure() to check if the request exceeds HTTPS and use the return value in the URL helper, for example:

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

Thus, you should automatically use HTTP or HTTPS depending on whether the current request uses HTTPS or not.

+3
source

All Articles