Last active
October 20, 2019 15:58
-
-
Save avosalmon/b447ed7f483714820ad812ae0e350a6e to your computer and use it in GitHub Desktop.
Get CDN asset URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this file goes on app/helpers/helpers.php?