laravel-datatables-html icon indicating copy to clipboard operation
laravel-datatables-html copied to clipboard

Editor-Html: Wrong image display url

Open frknakk opened this issue 5 years ago • 3 comments

Summary of problem or feature request

When I upload an image using the editor, the image is uploaded successfully but it is not displayed correctly in the modal.

More precisely, this only happens with URLs with multiple parts like "/admin/products". The JS part tries to load an image with "/admin/storage/image.jpg", which of course does not work. The right URL in this example would be "/storage/image.jpg".

Code snippet of problem

https://github.com/yajra/laravel-datatables-html/blob/4.0/src/Html/Editor/Fields/File.php#L54

return $this->display("function (file_id) { return file_id ? '<img src=\"storage/' + file_id + '\"/>' : null; }");

The easy solution which worked for me is to just add a / before storage:

return $this->display("function (file_id) { return file_id ? '<img src=\"/storage/' + file_id + '\"/>' : null; }");

In the long run, however, it will probably be better to load the concrete URL from the server.

System details

  • Debian 10
  • PHP 7.2
  • Laravel 6.14
  • Laravel-datatables-editor 1.18
  • Laravel-datatables-html 4.20

frknakk avatar Apr 24 '20 12:04 frknakk

I think adding a base href might fix your issue.

<base href="{{ url('/') }}">

Or override the script on display to fit your needs.

yajra avatar Apr 28 '20 01:04 yajra

In the long run, however, it will probably be better to load the concrete URL from the server.

I agree, if you can implement this, I would gladly accept a PR.

Also, I am also not yet satisfied on the current implementation of the Image field but can't dig it further atm. The current solution I made was a quick patch from a previous project.

yajra avatar Apr 28 '20 01:04 yajra

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 09 '22 03:10 github-actions[bot]

This issue was closed because it has been inactive for 7 days since being marked as stale.

github-actions[bot] avatar Oct 16 '22 04:10 github-actions[bot]