'unisharp laravel-filemanager Thumbnail url

Hi I'm using unisharp laravel-filemanager for user to upload their products photos

when the image uploaded

this address will save in database

/photos/44/606074649c651.jpg

and I can use it by

{{asset('storage/'.$product->cover_img)}}

and Thumbnail saved in this address

/photos/44/thumbs/606074649c651.jpg

How can I get the address of thumbnail and how can I use it in blade?

This is the answer

@php($lastSlash = strrpos($product->cover_img,"/"))

src="{{asset('storage/'.substr_replace($product->cover_img, 'thumbs/', $lastSlash+1) .'' .substr($product->cover_img ,$lastSlash+1))}}"


Solution 1:[1]

One way to save it in the database is to add a hidden type input to the image's thumb, inside the stand-alon-button.js file.

// set or change the preview image src

items.forEach(function (item) {
      target_preview.append(
         $('<img>').css('height', '5rem').attr('src', item.thumb_url),
         $('<input type="hidden" name="thumbnail">').attr('value', item.thumb_url)
      );
   });

Input:

<div class="input-group">
    <span class="input-group-btn">
        <a id="lfm" data-input="thumbnail" data-preview="holder" class="btn btn-primary">
           <i class="fa fa-picture-o"></i> Choose
        </a>
         </span>
         <input id="thumbnail" class="form-control" type="text" name="image">
</div>
<div id="holder" style="margin-top:15px;max-height:100px;"></div>

enter image description here enter image description here enter image description here

Solution 2:[2]

you can use a function like this:

function getThumbs($url=""){
    $base = basename($url);
    if (strpos($url, 'https://') !== false or strpos($url, 'http://') !== false) {
        return str_replace($base, "thumbs/".$base, $url);
    }else{
        $preUrl = "storage/";
        $beforeBase = str_replace($base, "",$url);
        return $preUrl.$beforeBase.'thumbs/'.$base;
    }
}

and in your blade use:

<img src="{{ getThumbs($product->cover_img) }}" .../>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Airon Gabriel
Solution 2 Ehsan