November 21, 2016 —John Koster
secure_asset($path)
The secure_asset
function will return a URI composed of the application's URI and the given $path
. It internally makes a call to the asset
(discussed in the Laravel URL Helper Function: asset article) helper function and always passes true
as the argument for the $secure
parameter.
The following:
1<?php2 3// https://laravel.artisan/js/application.min.js4secure_asset('js/application.min.js');
is equivalent to calling:
1<?php2 3// https://laravel.artisan/js/application.min.js4asset('js/application.min.js', true);
asset
and secure_asset
If the supplied $path
to asset
and secure_asset
contains a protocol, that protocol is used regardless of what function or flags are set. For example, if a URI with the http://
protocol is supplied to the secure_asset
function, the resulting URI will contain the http://
protocol. In addition, if a domain name is supplied to either of the functions, that domain name will be used instead of the domain present in the request.
1<?php 2 3// https://laravel.artisan/js/application.min.js 4asset('https://laravel.artisan/js/application.min.js', false); 5 6// http://laravel.artisan/js/application.min.js 7secure_asset('http://laravel.artisan/js/application.min.js'); 8 9// http://laravel.developer/js/application.min.js10asset('http://laravel.developer/js/application.min.js');
∎
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.