I noticed that when I used the Elixir helper function it returns an absolute path to the root of the server. I have a project that's located in a directory (http://server.test/project) and couldn't get my versioned css and js files to be loaded correctly.
In Illuminate\Foundation\helpers.php line 349 I changed
return '/'.$buildDirectory.'/'.$manifest[$file];
to
return url($buildDirectory.'/'.$manifest[$file]);
so that it would return a path relative to where my project is located.
This was the only way I found to get my project to correctly reference my versioned build files and it seems to me that the url() helper method should've been used here to begin with.
This has been suggested loads of times. Not sure why it's not changed in L5.3 yet. Ping @taylorotwell.
But how would you handle a custom domain for a file? I have some css on a CDN, so what I do is:
function cdnUrl()
{
return (config('settings.cdn')) ?: url('/');
}
function elixirCDN($file)
{
return cdnUrl() . elixir($file);
}
When the elixir() function automatically includes url() this will not work anymore...
@it-can Maybe the elixir function could support a new parameter;
function elixir($file, $url = false,$buildDirectory = 'build')
This way the return would check if the parameter exists or use the url() by default
return ($url ?: url('/')).'/'.$buildDirectory.'/'.$manifest[$file];
Then just call this in your function:
return elixir($file, cdnUrl()); //breakable change
//or
return elixir($file, 'build', cdnUrl()); //not so pretty
@fhb12345 I think changing the elixir() function to use url() and/or adding a url parameter to the elixir() function is breaking...
This has come up before. It's probably easier for people to just make their own function which exactly fits their individual requirements.
Most helpful comment
This has come up before. It's probably easier for people to just make their own function which exactly fits their individual requirements.