Framework: Ability to change the path to assets

Created on 14 Jun 2013  路  10Comments  路  Source: laravel/framework

Some of us might want to store assets in a sub-folder inside public/, e.g. public/assets. Changing the path should be possible with a configurable variable.

Most helpful comment

@taylorotwell I agree we can write another helper function to do this but it will be much convenient if we can override the default asset path as a setting in .env file. Can I send a PR?

All 10 comments

The path to assets isn't hardcoded. Just use asset('/assets/whatever.js')

True, but it shouldn't be too complex to add this single configurable option. It feels clumsy to include "assets" everywhere.

My assets are stored within different directories in my public folder though, so a single subfolder wouldn't make sense for me. Additionally I think just including it everywhere makes it much easier to understand where assets are stored rather than digging for some config option.

I can't imagine it would be very difficult to write your own helper function for this if you really want it.

Plus if you're looking to manage your assets a little more closely than what Laravel allows I'd just use something like Basset anyways.

Having a separate folder for all assets makes sense when you have a large amount of things, such as various libraries that you want to store in a folder of their own. There can easily be 5+ subfolders (e.g. CSS, JS, Bootstrap, Backbone, Prettify...) and while it may not matter for everyone, it certainly makes things cleaner when all the assets are combined in their own folder. I wouldn't say it's common practice but it's common enough for it to be taken into consideration.

Implementing this on my own is what I've done so far while working with Laravel. However, I thought I'd toss this issue here to see if anyone agrees with it being a small feature.

  1. how would one reference anything under than asset configurable folder, public() certainly not available.
  2. How would package asset be referred with this changes?
  3. If it follow the configurable folder, how does it being managed for package?

I don't know what you mean by referencing anything under that folder. If the path is set in the configuration, it can be accessed just like any other configurable option.

I don't know how packages work exactly, so I can't answer questions 2 & 3. In case this feature would prevent packages from working properly, I guess it then can't be added.

I recommend you to check out Basset too, I think this is a little more than what Taylor wants in the core.

You can write your own help function to do this.

@taylorotwell I agree we can write another helper function to do this but it will be much convenient if we can override the default asset path as a setting in .env file. Can I send a PR?

Was this page helpful?
0 / 5 - 0 ratings