mindhunter's avatar

How to concatenate string to a $variable in blade?

Hi guys. I'm hitting a problem and cannot solve it. here is my code:

  <div class="latest-news-img" style="background: url({{URL::asset('Images/ +$post->image)}}) no-repeat center top;background-size:cover;"></div>

How can i stick $post->image value to a directory of my image folder? The upper code give me a error. Thanks.

0 likes
3 replies
davielee's avatar
davielee
Best Answer
Level 11

@mindhunter You are using the wrong operator. In JS, the concatenation operator is +, but in PHP, it is .. To make your code above work, you would just have to update it to how it looks below.

<div class="latest-news-img" 
     style="background: url({{ URL::asset('Images/'.$post->image) }}) no-repeat center top; background-size: cover;">
</div>
1 like
Snapey's avatar

did you mean;

{{URL::asset('Images/' . $post->image)}}

3 likes

Please or to participate in this conversation.