1 month ago

How to pass image path inside javascript when calling with symlink in laravel

Posted 1 month ago by Jonjie

I'm trying to pass a path inside <img> tag with symlink approach and it works just fine but when I pass it in javascript, it return CORS policy error. Im using laravel 7 so it should automatically give access, and the allowed_origins is also set to *.

This error only occurs when I run php artisan serve but there is no error when I use valet.

JS Code

$options['url'] = "{{ auth()->user()->getCoverPhoto() }}";
$image_crop = $('#imageDemo').croppie($options);


enter image description here


Access to image at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

P.S. I've read a lot running php artisan storage:link but I already done that. And it shouldn't be the solution since I already can access the image through <img> tag but it's not working when I access it inside Javascript.


When I try url('/') . '/users-images/images/f223444da2d28eec731f7e8f39278c7a.jpeg', It gives me 404 error.

Please sign in or create an account to participate in this conversation.