简体   繁体   中英

Displaying Laravel Voyager Images in templates

Per their instructions, I'm attempting to pull out my images uploaded through admin with this:

{{ Voyager::image( $brand->logo ) }}

Instead of getting a url, it instead gives me an url with an appended JSON item:

http://job-tool.test/storage/[{"download_link":"brands\/April2018\/3Yrma1PZogiMiYOFmPGg.png","original_name":"logo_petiq.png"}] 

PetIQ

Running just {{ $brand->logo }} gives me the array without the prepended url. What am I missing here?

I've also attempted to just use this: {{ Voyager::image( $brand->logo->download_link ) }} but I receive this error:

Trying to get property 'download_link' of non-object (View: /Users/johnbriggs/Code/Laravel/job-tool/resources/views/brands/show.blade.php)

How about trying;

{{ Voyager::image( $brand->logo->download_link ) }}

Having looked at the voyager package the Voyager::image function is

   public function image($file, $default = '')
    {
        if (!empty($file)) {
            return Storage::disk(config('voyager.storage.disk'))->url($file);
        }
        return $default;
    }

So could you try something like

<?php 
$file = (json_decode($brand->logo))[0]->download_link;
?>
{{ Voyager::image( $file ) }}

Although I appreciate this is a less than clean approach.

Had the same problem one year later. The above answer by Simon R worked fine for me. Just echo the decoded json inside an image tag. Something like this:

    <img src="{{ Voyager::image( $file ) }}">

Try this :

{{Voyager::image($article->thumbnail('medium','cover'))}}

And this is the validation of the cover field in Voyager :

{
    "resize": {
        "width": "728",
        "height": null
    },
    "quality": "80%",
    "upsize": true,
    "thumbnails": [
        {
            "name": "medium",
            "scale": "50%"
        },
        {
            "name": "small",
            "scale": "27%"
        }
    ],
    "validation": {
        "rule": "required"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM