How to add dynamic src image with Larav blade

My question is very simple. I use laravel's blade to display images like

<img src="{{asset('assets/images/image.jpg')}}"> 

but what if my image is dynamic, for example:

 <img src="{{asset('assets/images/$imgsrc')}}"> 

I can not use

  <img src="{{asset('assets/images/{{ $imgsrc')}}"> 

because then I finish with:

  <img src="http://localhost/assets/images/{{ $imgsrc"> 

How can I call the $ variable in the click {{}}?

+6
source share
2 answers

What about

 <img src="{{asset('assets/images/').'/'.$imgsrc}}"> 

EDIT

when you need to print several lines where variables, functions can be ... you need to concatenate them

Also asset('assets/images/') equivalent to asset('assets/images') , so you need to add / before printing the $imgsrc variable

Finally, in Blade, {{"foo"}} equivalent to <?php echo "foo" ?>

+10
source

How can I call the $ variable in the click {{}}?

The usual way of PHP. The blade {{}} is simply balancing <?php echo() ?>

So the answer to your question is:

 <img src="{{ asset('assets/images/' . $imgsrc) }}"> 
+3
source

Source: https://habr.com/ru/post/969437/


All Articles