Generating a Secure HTML Link


You want to generate a secure HTTPS link in your Blade template.


Use the HTML::secureLink() method.

This only works correctly when you're building URLs for your application. In other words, if you pass a fully formed URL to the method, it will use the fully formed URL.

You pass paths to this method, not URLs.

If you only pass the path as the first argument it will create a link using the full URL as the title.

{{ HTML::secureLink('x') }}

This produces the following HTML.

<a href="https://your.url/x">https://your.url/x</a>

You can specify the title as the second argument.

{{ HTML::secureLink('a/b', 'A-B') }}

The resulting HTML is below.

<a href="https://url.url/a/b">A-B</a>

You can also pass an array of attributes as the third argument.

{{ HTML::secureLink('login', 'Sign In', array('class' => 'btn')) }}

Now the anchor tag has a class attribute.

<a href="https://your.url/login" class="btn">Sign In</a>


This method is a wrapper for HTML::link().

But it always passes true as the fourth argument to HTML::link().

See Generating a HTML Link for details.

comments powered by Disqus