Search code examples
laravellaravel-bladevoyager

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)

Solution

  • 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.