'How do i include an echo statement inside another Echo statement in laravel

<img src="{{ asset('public/image/{{$blog->image}}') }}" alt="post image">

this gives a parse error PHP 8.1.2 9.3.1 Unclosed '(' does not match '}' please how can i nest that {{$blog->image}} inside the image src without getting an error, thanks



Solution 1:[1]

{{ }} behaves as an echo statement so you can't add echo in another echo. You just have to concatenate the string with variable like:

<img src="{{ asset('public/image/' . $blog->image) }}" alt="post image">

Solution 2:[2]

You can concatenate strings with . just like in PHP.

When you use {{ }} inside a Blade template, it is like using echo in PHP. Just concatenate them with a . (dot).

<img src="{{ asset('public/image/' . $blog->image) }}" alt="post image">

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mian Saqlain
Solution 2 Kirk Beard