Displaying Laravel Voyager Images in templates

brunam picture brunam · Apr 13, 2018 · Viewed 8.3k times · Source

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)

Answer

Simon R picture Simon R · Apr 14, 2018

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.