Support the ongoing development of Laravel.io →
Requests Views Blade
Last updated 1 year ago.
0

just the matter of desire i guess :D

<link rel="stylesheet" href="<?php echo URL::asset('assets/css/app.css')?>">
Last updated 1 year ago.
0

You must note that, in many cases, your examples above could produce different results.
URL helpers always refer to the Laravel application base path, and that's the main advantage IMO.
Let's say your application base is /larapp. Let's say you are returning a view for /some/route. Let's say the stylesheet is in /larapp/assets/css. You don't easily get to that without URL helpers:

<link rel="stylesheet" href="assets/css/app.css">
<!-- http://your.host/larapp/some/route/assets/css/app.css
NOT FOUND -->

<link rel="stylesheet" href="/assets/css/app.css">
<!-- http://your.host/assets/css/app.css
NOT FOUND (but still ok when the app base is "/" and won't change) -->

<link rel="stylesheet" href="../../assets/css/app.css">
<!-- http://your.host/larapp/assets/css/app.css
OK BUT this kind of relative url is bad (search the web for more info) and above all you have to take into account the actual route -->

<link rel="stylesheet" href="/larapp/assets/css/app.css">
<!-- http://your.host/larapp/assets/css/app.css
OK BUT if the app base changes to "/gotcha/larapp" at some point, you'll have to rewrite it (e.g. do a find-replace) -->

{{ HTML::style('assets/css/app.css') }}
<!-- <link rel="stylesheet" href="http://your.host/larapp/assets/css/app.css";>
I GO WITH THIS ONE -->

Of course, the advantages of url helpers for actions and routes are way more evident.

Last updated 1 year ago.
0

Thank you popolla. Of course that makes sense. I have been using HTML::style(), HTML::link(), ... in all my Projects so far, so I didn't see the downside of

<link rel="stylesheet" href="assets/css/app.css">

:-)

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

hettiger hettiger Joined 17 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.