Skip to content

Instantly share code, notes, and snippets.

@lytedev
Last active August 29, 2015 14:08
Show Gist options
  • Save lytedev/1b221584ce872b3e323e to your computer and use it in GitHub Desktop.
Save lytedev/1b221584ce872b3e323e to your computer and use it in GitHub Desktop.
Custom Laravel elixir function
<?php
if ( ! function_exists('elixir'))
{
/**
* Get the path to a versioned Elixir file.
*
* @param string $file
* @return string
*/
function elixir($file)
{
static $manifest = null;
if (is_null($manifest))
{
$manifest = json_decode(file_get_contents(public_path().'/build/rev-manifest.json'), true);
}
if (isset($manifest[$file]))
{
if (App::environment('production'))
{
return asset('build/'.$manifest[$file]);
}
else
{
return asset($file);
}
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment