I find sometimes both is OK? So what's the really difference?
For example,
<link rel="stylesheet" href="{{asset('resources/views/admin/style/css-ui.admin.css')}}">
and
<link rel="stylesheet" href="{{url('resources/views/admin/style/font/css/font-awesome.min.css')}}">
these two form is both OK.
So, what's the differences?
Laravel provides a helper function, asset() , which generates a URL for your assets. You can use this in blade syntax, e.g. <script type="text/javascript" src="{ { asset('js/jquery.js') } }"></script>
Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which allows Laravel to verify that the URL has not been modified since it was created.
You can configure the asset URL host by setting the ASSET_URL variable in your . env file. Show activity on this post. Show activity on this post.
echo base_url(); to get my site's URL.
Consider the type of URL that is needed / how the URL is being used. One of the advantages of having separate helper methods for each type of URL is they can have different handling logic. For example, assets (e.g. CSS, images, etc.) could involve a check that the file exists in the file system but do not require the type of analysis that a route would because the route may have parameters.
Preserves any URL query string.
{{ url('search') }} // http://www.example.com/search {{ url('search', ['qevo', 'laravel']) }} // http://www.example.com/search/qevo/laravel
Only accepts a direct path.
{{ asset('css/app.css') }} // http://www.example.com/css/app.css
Allows override for relative route vs. absolute route (default).
{{ route('user.profile', ['name'=>'qevo']) }} // http://www.example.com/user/qevo/profile {{ route('user.profile', ['name'=>'qevo'], false) }} // /user/qevo/profile
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