New basset() helper (yes, helper)

As part of Backpack v6, we've invented a new way of loading assets in Laravel. And we've done that as an open-source package - one that...

Cristian Tabacitu
Cristian Tabacitu
Share:

As part of Backpack v6, we've invented a new way of loading assets in Laravel. And we've done that as an open-source package - one that we hope Laravel devs will use outside Backpack projects too. If you don't know about it, we call it Basset. Basically you could do:

@basset('https://path/to/file.css')

And it will internalize that file, make it public in your app and output:

<link href="https://yourapp.com/storage/path/to/file.css">

What's new?

We've been getting some VERY useful feedback on this package on the Laracasts forum. In fact, just a few days after we got feedback there, we launched Basset 1.20. Thanks to the idea and the PR from there, we now have a helper too. You can now do:

<link href="{{ basset('https://path/to/file.css') }}">

What's the benefit?

This is such a simple thing, right? Why all the fuss? Well... even though the change looks small, it is very important. It is so important in fact... that we're ashamed we hadn't thought of it before 😅

First of all, it's super-similar with Laravel's asset() helper. That makes it easy to understand and easy to use. Just do a find-and-replace in your blade views, from asset( to basset( and boom. You're using Basset everywhere 🤯

Secondly, it allows you to load other filetypes than CSS and JS - any other filetype. That is HUGE too. Because you choose where that asset is used (you have the path), you can use it on images, videos, audio files... even pdfs or something else. Basset will internalize it (copy it to a public directory) and you can use it.

Thirdly, it allows you to use it outside blade files. That's right, if you want to internalize a file in your Controller... you can do that now! Should you? I don't know. But you can! 😅

Who's to thank?

We're super-grateful for everyone involved in this small but important PR:

We love this helper so much, that we've made it the default way to use Basset. We instruct people on how to use basset() first, then @basset().

If you have more ideas on how we can improve Basset, please let us know. We're committed to making this package more and more awesome.

Cheers!

Want to receive more articles like this?

Subscribe to our "Article Digest". We'll send you a list of the new articles, every week, month or quarter - your choice.

Reactions & Comments

What do you think about this?

Latest Articles

Wondering what our community has been up to?