For loading assets in Laravel 4 projects there is a helper to create a URL for an asset
<link rel="stylesheet" href="{{ asset('css/styles.css') }}" />
But that helper could be called using a facade too
<link rel="stylesheet" href="{{ URL::asset('css/styles.css') }}" />
which produce the same result.
So my question is, which is the real difference here, one way is better in terms of performance than the other or is just a preference style ??
This is the asset()
function:
if ( ! function_exists('asset'))
{
/**
* Generate an asset path for the application.
*
* @param string $path
* @param bool $secure
* @return string
*/
function asset($path, $secure = null)
{
return app('url')->asset($path, $secure);
}
}
Both of the functions are, therefore, the same. asset()
is simply a helper function. Specifically, helpers are more appropriate for views. So, yes, it is a preference thing. I tend to prefer using Facades.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With