Laravel: What's the advantage of using the asset method in blade pages? Laravel: What's the advantage of using the asset method in blade pages? laravel laravel

Laravel: What's the advantage of using the asset method in blade pages?


If you do the latter, the URLs will not work when you're on any URL that includes a forward slash. E.g. not using asset will appear to work fine if you're on the homepage, but if you were on /search/results or whatever, the URLs won't be correct (as it'll be looking for /search/icons/favicon-32x32.png).


It helps you to generate a valid URL for your assets.

If you use asset('icons/favicon-32x32.png'), it will always create application related URL's irrespective of the position of the installation folder of your app in the server.

For example, if your application is hosted in a subfolder instead of the root directory, if you use asset method, laravel will create the related path for the asset.