Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

concatenate Php variable with String inside img src

I am using Laravel blade. i want to concatenate a php variable with string inside blade code.

for Example in js:

  <img class="img-responsive" src='http://example.com/'+ user_id +'/picture?type=square';/>

how to write this with php variable?

  <img class="img-responsive" src='http://example.com/'. {{ $user_id}} .'/picture?type=square';/>
like image 472
Neha Avatar asked Jan 02 '23 20:01

Neha


2 Answers

You can do this:

<img src="http://example.com/{{ $user_id }}/picture?type=square">

Or:

<img src="{{ 'http://example.com/' . $user_id . '/picture?type=square'}}">

But it's always a good idea to use asset() helper for this:

<img src="{{ asset($userId . '/picture?type=square') }}">
like image 55
Alexey Mezenin Avatar answered Jan 05 '23 15:01

Alexey Mezenin


You need to write it like this:

 <img class="img-responsive" src='http://example.com/{{ $user_id }}/picture?type=square';/>

You don't need to concatenate using . in Blade.

like image 37
Amit Merchant Avatar answered Jan 05 '23 14:01

Amit Merchant