how to add a dynamic image src with laravels blade

前端 未结 3 953
一生所求
一生所求 2021-02-15 16:37

My question is very simple. i use blade in laravel to show the images like


but what

相关标签:
3条回答
  • 2021-02-15 17:10

    How can i call to a $variable in a blade {{}} call?

    The normal PHP way. A blade {{}} is just the equilivant of <?php echo() ?>

    So the answer to your question is:

    <img src="{{ asset('assets/images/' . $imgsrc) }}">
    
    0 讨论(0)
  • 2021-02-15 17:19

    How about

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

    EDIT

    when you need printing more than one strings where there may be variables,functions... you need to concatenate them

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

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

    0 讨论(0)
  • 2021-02-15 17:32

    Mine had multiple dynamic parts in the src and this is how I did it after getting in the right direction, thanks to @Laurence's answer.

    <img src="{{asset('storage/'.$parentFolderName.'/'. $clientNameFolder .'/logo/').'/'.$event[0]->event_logo}}" class="event-page-country-logo">
    
    0 讨论(0)
提交回复
热议问题