diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index 39f0da2391f0..8d99eca5d374 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -385,19 +385,28 @@ function dispatch($job) */ function elixir($file, $buildDirectory = 'build') { - static $manifest; + static $manifest = []; static $manifestPath; - if (is_null($manifest) || $manifestPath !== $buildDirectory) { - $manifest = json_decode(file_get_contents(public_path($buildDirectory.'/rev-manifest.json')), true); + if (empty($manifest) || $manifestPath !== $buildDirectory) { + $path = public_path($buildDirectory.'/rev-manifest.json'); - $manifestPath = $buildDirectory; + if (file_exists($path)) { + $manifest = json_decode(file_get_contents($path), true); + $manifestPath = $buildDirectory; + } } if (isset($manifest[$file])) { return '/'.trim($buildDirectory.'/'.$manifest[$file], '/'); } + $unversioned = public_path($file); + + if (file_exists($unversioned)) { + return '/'.trim($file, '/'); + } + throw new InvalidArgumentException("File {$file} not defined in asset manifest."); } } diff --git a/tests/Foundation/FoundationHelpersTest.php b/tests/Foundation/FoundationHelpersTest.php index 82a7b81f3f65..2d324ebd4623 100644 --- a/tests/Foundation/FoundationHelpersTest.php +++ b/tests/Foundation/FoundationHelpersTest.php @@ -37,4 +37,19 @@ public function testCacheThrowsAnExceptionIfAnExpirationIsNotProvided() cache(['foo' => 'bar']); } + + public function testUnversionedElixir() + { + $file = 'unversioned.css'; + + app()->singleton('path.public', function () { + return __DIR__; + }); + + touch(public_path($file)); + + $this->assertEquals('/'.$file, elixir($file)); + + unlink(public_path($file)); + } }