I’m making a website on Nuxt 3
+ Laravel
(backend). I have an article editor where I can upload an image. I need to compress and crop this image for several different formats. Then, I will take the desired format depending on where it is output. Nuxt
and Laravel
are located in different folders on the server, with different urls. Questions:
- Where should I store images – in
Nuxt
orLaravel
?
If in Laravel
, then:
- How do I access them from
Nuxt
? - How can I specify the paths to the images, given that the site is currently accessed via the local path –
localhost:8000
? I need the images not to disappear when I publish the site on the internet.
2
Answers
Try @storage directive
Assuming your image file is located in the images directory of Laravel’s storage directory. The @storage() directive will automatically resolve the path to the image file and return it as a string.
The decision of where to store images depends on your specific use case and requirements. you can store static images like (Banner icons) on NuxtJS side and dynamic images like (user documents, product images, and avatars) on the Laravel side.
So on the Laravel side, you can use file functions and store images in a storage folder after that create a storage link (PHP artisan storage:link) after that create API and return the full image path in the response object.
In NuxtJS you can utilize the with some configuration.
https://image.nuxtjs.org/configuration