Neh*_*eha 4 php image concatenation laravel laravel-blade
我正在使用 Laravel 刀片。我想将 php 变量与 Blade 代码中的字符串连接起来。
以js为例:
<img class="img-responsive" src='http://example.com/'+ user_id +'/picture?type=square';/>
Run Code Online (Sandbox Code Playgroud)
如何用 php 变量写这个?
<img class="img-responsive" src='http://example.com/'. {{ $user_id}} .'/picture?type=square';/>
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
<img src="http://example.com/{{ $user_id }}/picture?type=square">
Run Code Online (Sandbox Code Playgroud)
或者:
<img src="{{ 'http://example.com/' . $user_id . '/picture?type=square'}}">
Run Code Online (Sandbox Code Playgroud)
asset()但为此使用 helper 总是一个好主意:
<img src="{{ asset($userId . '/picture?type=square') }}">
Run Code Online (Sandbox Code Playgroud)