laravel-theme icon indicating copy to clipboard operation
laravel-theme copied to clipboard

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

Open leenooks opened this issue 6 years ago • 4 comments

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, '/');
...

leenooks avatar Jun 02 '19 00:06 leenooks

Fixed!

igaster avatar Jul 03 '19 05:07 igaster

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;
         }
 ...

leenooks avatar Jul 17 '19 04:07 leenooks

@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?

igaster avatar Oct 11 '19 18:10 igaster

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>

leenooks avatar Oct 11 '19 21:10 leenooks