Editor-Html: Wrong image display url
frknakk opened this issue · 4 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
I think adding a base href might fix your issue.
<base href="{{ url('/') }}">
Or override the script on display to fit your needs.
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.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 7 days since being marked as stale.