/**
  * Generate a URL to an application asset.
  *
  * @param  string  $path
  * @param  bool    $secure
  * @return string
  */
 protected function configAssetUrl($path, $secure = null)
 {
     static $assetUrl;
     // Remove this.
     $i = 'index.php';
     if (URL::isValidUrl($path)) {
         return $path;
     }
     // Finding asset url config.
     if (is_null($assetUrl)) {
         $assetUrl = \Config::get('theme.assetUrl', '');
     }
     // Using asset url, if available.
     if ($assetUrl) {
         $base = rtrim($assetUrl, '/');
         // Asset URL without index.
         $basePath = str_contains($base, $i) ? str_replace('/' . $i, '', $base) : $base;
     } else {
         if (is_null($secure)) {
             $scheme = Request::getScheme() . '://';
         } else {
             $scheme = $secure ? 'https://' : 'http://';
         }
         // Get root URL.
         $root = Request::root();
         $start = starts_with($root, 'http://') ? 'http://' : 'https://';
         $root = preg_replace('~' . $start . '~', $scheme, $root, 1);
         // Asset URL without index.
         $basePath = str_contains($root, $i) ? str_replace('/' . $i, '', $root) : $root;
     }
     return $basePath . '/' . $path;
 }
Exemplo n.º 2
0
 public static function makeRelative($url)
 {
     return ($base = Request::getHttpHost()) ? str_replace(Request::getScheme() . $base, '/', $url) : $url;
 }