Hey guys,
I was just wondering whether there were plans to add an asset root configuration variable to allow us to have an asset root separate to the main site (i.e. through a CDN or such) for methods such as $app['url']->asset() and URL::asset().
I wasn't sure about how to go about this in a "Laravel" way, or if it was planned already...
I would really like something like that too. When removing the public part from the url on production, as ->asset only removes the index.php part, all assets end becoming 404. This was solvable in Laravel 3 with the asset_url config variable but in Laravel 4 I had to manually reroute files ending in certain extensions to the public/ folder.
I agree this would be a pretty handy addition.
+1
I think asset management should not be feature full in Laravel. There are plenty of other good asset management packages out there such as Bassett and Assetic which are better to use. No point competing
I am not asking for a full asset management system in Laravel, just that there is a configuration option for assets so that you may use URL::asset() to use a different domain/webroot for assets.
See https://github.com/jasonlewis/basset/blob/master/src/Basset/Basset.php#L69 for the fact that Basset, that you mentioned, uses $app['uri']->asset() to generate asset URLs.
Oh I know that Basset uses L4 for locating assets, my point was that L4 shouldn't be trying to be a jack of all trades. With so many good composer packages we should be trying to de-framework where possible.
But I guess adding a custom base URL for assets isn't really going to hurt anybody :)
Ah ok, I agree with that!
Sorry if I came across a little terse!
+1
+1
I agree with this one.
+1. This would be incredibly useful.
:+1: looking forward to see this implemented
You guys can stop +1ing and post how you want to see it implemented :wink:
I think the way Laravel 3 is handling it is fine, no need for anything more in my opinion.
At the moment, I'm just using a little helper like so, which does the job well:
/**
* Get the URL to an asset
*
* @param string $asset
*
* @return string
*/
function ass($asset)
{
return asset('asset/' . ltrim($asset, '/'));
}
Maybe the helper asset($string) could be moved into the /app directory like so, so anyone can just change the $root if needed.
/**
* Generate an asset path for the application.
*
* @param string $path
* @param bool $secure
* @param string $root
* @return string
*/
function asset($path, $secure = null, $root = '/asset/')
{
$app = app();
$url = $app['url']->to($root);
return $app['url']->asset($url . ltrim($path, '/'), $secure);
}
I think making a configuration option just for this would be too much overhead.
Didn't @ianlandsman once post a nice suggestion with a way to just
configure a bunch of URLs with a certain key that you could use in certain
places like for assets etc.? That would also make things like multiple
asset hosts possible.
On Sun, Feb 17, 2013 at 1:32 PM, Conrad Kleinespel <[email protected]
wrote:
At the moment, I'm just using a little helper like so, which does the job
well:/** * Get the URL to an asset * * @param string $asset * * @return string */ function ass($asset) { return asset('asset/' . ltrim($asset, '/')); }—
Reply to this email directly or view it on GitHubhttps://github.com/laravel/framework/issues/121#issuecomment-13685188.
What about having named asset locations, and the ability to get them using a facade like Asset::
Honestly I would just suggest creating a little cdn helper function or whatever for your own projects. We do that and it's a simple way to accomplish something like this without baking something into the framework.
A quick note if Google took you here looking for some way to configure the asset URL. I haven't been able to find it in the documentation, but Taylor documents it here: https://twitter.com/taylorotwell/status/1062805944147628032?s=20
Long story short, you can add a config option to append a custom asset root URL now.
Edit config/app.php and add a line like this:
'asset_url' => env('ASSET_URL', null),
And it will be magically handled by RouteServiceProvider::registerUrlGenerator().