0

I am doing some tiny stuffs in reactjs in a blade file of laravel. I just add react cdn and writing code within script tag. All looks good except I stuck at a point of showing image from public/assets/img folder of laravel using reactjs.

Any help is appretiated. Thanks

3 Answers 3

1

You need to use the source link of your image.

For example, if laravel expose those static files under http://localhost/public/asset/img, then you need to write in your JSX:

<img src="http://localhost/public/asset/img/test.jpg" alt="test" />
Sign up to request clarification or add additional context in comments.

2 Comments

In that case I am getting dependent in the source code. If my host get changes I would need to edit everywhere I used it. Think about laravel asset() function where I dont need to change anything even if host changes.
Abdur Rahman, react does not provide anything else than a virtual DOM, if you want to add some configuration, you should create a configuration variable with what you need for booting your react app. You could use the context to broadcast down your react tree when you need it. Another option would be to use <base /> tag
0

Dimitri Kopriwa's answer didn't work for me because including public in the image path meant I was repeating it twice. When you start a PHP project you're already in the public directory so using this worked for me:
http://localhost:8000/documents/pictures/${image}

Comments

0

it's simple, if your image is located in public/assets/img, write this in your jsx:

<img src="http://localhost/public/asset/img/image.png" alt="image" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.