-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.5] Allow to custom assets root URL #22372
Conversation
I thought we had some way to do this already? Am I wrong? @themsaid |
I'm not aware of this feature already existing, hence why I had to define as a quick hack:
|
@taylorotwell we have
and it will generate:
Looking at @GrahamCampbell's custom method, I think we can have a config value instead of the proposed |
Yeah, it seems the only built-in way to do this is using <script src="{{ app('url')->assetFrom(config('app.assets_url'), 'js/app.js') }}"></script> In my opinion, there is no reason to code: <script src="{{ asset('js/app.js') }}"></script> instead of: <script src="/js/app.js"></script> I don't know how users use the
@themsaid It would be wonderful if we can have a config value, I wondered my PR will be rejected if I introduce a new config like $this->app->singleton('url', function ($app) {
$url = new UrlGenerator(...);
$url->setAssetsRoot($app['config']['app.assets_url']);
// ...
}); |
I'm not sure we need to add anything to the framework for this. You can already define your own specific helpers that use |
@taylorotwell As I said in the PR description, for the vendor packages shipping with assets, for example laravel-adminlte, users need to publish package's assets then replace all I think It is a small and harmless code change, but with big help and conveniences. Currently the url('blog', $post)
url('js/app.js')
url(mix('css/main.css')) @themsaid @GrahamCampbell How do you think? |
A workaround: define
|
This PR adds support to custom the root URL for generating assets URLs, now we can use the built-in
asset()
orsecure_asset()
methods to generate an independent domain or CDN URL.I think this is helpful for framework users because using independent domain or CDN for assets is a very common thing for web apps. And for now it is hard to extend the
UrlGenerator
or the coreRoutingServiceProvider
to achieve this, right?Why not just define my own
asset_url()
orcdn()
helper?Some packages publish their assets to the public path, and use the
asset()
method to ref them. If I want them cookie-free or to load from a cloud storage, I need to runvendor:publish
even I just want to changeasset()
tocdn()
, and I need to re-publish & modify every time these packages update.