Skip to content

Instantly share code, notes, and snippets.

@avosalmon
Last active October 20, 2019 15:58
Show Gist options
  • Save avosalmon/b447ed7f483714820ad812ae0e350a6e to your computer and use it in GitHub Desktop.
Save avosalmon/b447ed7f483714820ad812ae0e350a6e to your computer and use it in GitHub Desktop.
Get CDN asset URL
<?php
if (! function_exists('asset_path')) {
/**
* Get the path to a versioned Mix file.
*
* @param string $path
* @param string $manifestDirectory
* @return \Illuminate\Support\HtmlString|string
*
* @throws \Exception
*/
function asset_path($path, $manifestDirectory = '')
{
$mixPath = mix($path, $manifestDirectory);
$cdnUrl = config('assets.cdn_url');
$env = config('app.env');
// Reference CDN assets only in production or staging environemnt.
// In other environments, we should reference locally built assets.
if ($cdnUrl && ($env === 'production' || $env === 'staging')) {
$mixPath = $cdnUrl . $mixPath;
}
return $mixPath;
}
}
@angelorodem
Copy link

this file goes on app/helpers/helpers.php?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment