E
E
Emil Rakhmatullin2020-09-03 15:57:04
Laravel
Emil Rakhmatullin, 2020-09-03 15:57:04

How to get image from Laravel Storage in Vue component?

I save the image in storage/app/public/posts/image.png.
The path to the image in the database public/posts/image.png.

I successfully get the picture in the blade template through Storage::url($post->image)
A in the component as in the blade does not work. In the component, I receive a post in JSON format (like <my-post :post='@json($post)'></my-post>)

The path to the photo does not work (it's understandable). How do I change the link so that the JSON post already has a working link (which is generated by Storage::url($post->image))?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
guruloz, 2020-09-03
@Emchik

In the database, you need to save posts/image.png, without public
And already in the component, you need to access the path to the file, adding storage to the beginning , i.e. - But, the best thing is to write a Laravel Resource for the post, and inside it it is already correct to cast the path using the asset helper , for example, or Storage::url , and already pass the data to the view component processed by this resource. `/storage/${post.image}`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question