igaster / laravel-theme

Theme support for Laravel
MIT License
516 stars 110 forks source link

Argument 2 passed to Orchestra\Asset\Asset::style() must be of the type string #111

Open leenooks opened 5 years ago

leenooks commented 5 years ago

Hi, if you use @css or @js with a url without http(s), it results in the above error. EG: @css('//cdn/file') or @js('//cdn/file')

A fix I propose for this is to modify Theme.php, and in the function url(), add the following to the beginning of the function:

    public function url($url)
    {
        // return external URLs unmodified
        if (preg_match('#^//#',$url))
                return $url;

        $url = ltrim($url, '/');
...
igaster commented 5 years ago

Fixed!

leenooks commented 5 years ago

BTW: I needed to apply the same fix to the url() function in src/Themes.php

IE:

 // Return url of current theme
    public function url($filename)
    {
         if (preg_match('/^((http(s?):)?\/\/)/i', $filename)) {
            return $filename;
         }
 ...
igaster commented 4 years ago

@leenooks why is this broken?

this line: https://github.com/igaster/laravel-theme/blob/master/src/Themes.php#L319

will call the Theme::url() which should return the correct value. Unless you didn't set some active theme. Is that your case?

leenooks commented 4 years ago

Without my patch, when you have @js('https://my.javascript.url/to/a/jsfile') results it being rendered as a path, ie: <script src="https://my.web.url/https://my.javascript.url/to/a/jsfile"></script>