Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 difference between URL::asset() and asset()

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 ??

like image 264
Javier Cadiz Avatar asked Dec 13 '13 04:12

Javier Cadiz


1 Answers

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.

like image 158
Mike Rockétt Avatar answered Oct 10 '22 16:10

Mike Rockétt