use named route and asset in controller i am trying to get the image and also set a named route in my controller
foreach($users as $user){
$output .= '
<tr>
<td >'.$user->id.'</td>
<td>
<img src="{{ asset("storage/images/avatar5.png") }}" > //here ?? <-------------
</td>
<td>'.$user->name.'</td>
<td>
<a href="{{route("admin.viewUser",["id"=>'. $user->id .'])}}" class="btn d-inline">
</a> //here ?? <-------------
</td>
</tr>
';
}
You are using blade tags inside your controller which is not valid. You should use the regular php syntax instead, just like you are doing inside the td.
The {{ $variable }} syntax is just sugar code for .
<img src=" . asset('storage/images/avatar5.png') . ">
<a href=" . route('admin.viewUser', ['id' => $user->id]) . " class="btn d-inline"></a>
<a href="{{ route('admin.viewUser', $user->id) }}" class="btn d-inline"></a> // Does not have to pass a array when its only 1 value
Assets require a bit of digging also the php artisan storage:link has to be used
@Cruorzy i already used php artisan storage:link .. i was using the code in my blade template and it works ..but now i needed to move it to my controller
Oh wouw, you are outpussing html from the controller?
Would not have noticed that..
foreach($users as $user){
$output .= '
<tr>
<td >'.$user->id.'</td>
<td>
<img src="{{ asset("storage/images/avatar5.png") }}" > //here ?? <-------------
</td>
<td>'.$user->name.'</td>
<td>
<a href="{{route("admin.viewUser",["id"=>'. $user->id .'])}}" class="btn d-inline">
</a> //here ?? <-------------
</td>
</tr>
';
}
Please sign in or create an account to participate in this conversation.