Search

Laravel 5: Generating HTTPS URLs With secure_url

April 14, 2018 —John Koster

The secure_url helper function can be used to generate secure, fully qualified URLs to a given $path. You can also supply additional data that will be added as a query string by supplying an argument for the $parameters parameter.

The secure_url helper function internally returns the value of a call to the url helper function.

#Signature

The signature of the secure_url function is:

1function secure_url(
2 $url,
3 $parameters = []
4);

#Example Use

The following example demonstrates the usage of the secure_url helper function:

1$url = secure_url('arbitraryPath');
2 
3// The previous example is equivalent to:
4$otherUrl = url('arbitraryPath', [], true);

The resulting URL would look similar to the following output. The exact URL will change depending on the $path and the domain name.

1https://laravel.artisan/arbitraryPath

To generate URLs with extra data, supply an argument for the $parameters array like so:

1$url = secure_url('arbitraryUrl', [
2 'someParameter'
3])

The resulting URL would be similar to the following output:

1https://laravel.artisan/arbitraryUrl/someParameter

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.