Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4: Getting URL::route to returns a HTTPS URL without enforcing HTTPS in the routes

I want all the links on my site to use HTTPS; however I cannot (for non technical reasons) force users to use HTTPS. I therefore want all URLs generated by Laravel to be prefixed with 'https', but I don't want Laravel to throw an exception if a user visits the URL over 'http'.

I have the following route setup:

Route::get('dashboard', [ 'uses'=>'DashboardController@view' ]);

Can anyone tell me how to get URL::route('dashboard') to return a HTTPS version of the URL, without rewriting my route as:

Route::get('dashboard', [ 'https', 'uses'=>'DashboardController@view' ]);

Or how to write my route as per the second example, but not thrown an exception if then accessed over 'http'?

like image 865
Neil Avatar asked May 06 '26 08:05

Neil


1 Answers

For creating an https link in a laravel blade view with URL::route , simply use: URL::secure()

http://cheats.jesse-obrien.ca/#urls

URL::secure('foo/bar', $parameters);
URL::secureAsset('css/foo.css');
URL::to('foo/bar', $parameters, $secure);
like image 90
Maurice Avatar answered May 08 '26 05:05

Maurice



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!