Reputation: 294
I am a Laravel newbie and this is my problem. I have this piece of code below that works inside my controller.
public function home()
return view('/home', [
'image' => 'img/ctewzvv-aweadyojaae1cwbrvlo192.png',
]);
}
Inside my partial is this:
<div class="img-container">
<a href="#">
<img src="{{ asset( $image ) }}" alt="image">
</a>
</div>
They work perfectly fine. My question is what if I have multiple image paths that I want to display inside a list like this:
public function home() {
$images = ['img/ctewzvv-aweadyojaae1cwbrvlo192.png','img/abcwzvv-aweadyojaae1cwbrvlo192.png','img/vbfwzvv-aweadyojaae1cwbrvlo192.png'];
return view('/home', [
'images' => $images
]);
}
Would the above code possible?
Or what if I have all the images contained inside a folder, would it be possible if I display them at once? Thanks in advance. Help is much appreciated. Please respect.
Upvotes: 1
Views: 2324
Reputation: 1301
Yes you can add a loop in your blade file and show all the images:
@foreach($images as $image)
<img src="{{ asset( $image ) }}" alt="image">
@endforeach
Upvotes: 1
Reputation:
you should try this:
public function home() {
$images = ['img/ctewzvv-aweadyojaae1cwbrvlo192.png','img/abcwzvv-aweadyojaae1cwbrvlo192.png','img/vbfwzvv-aweadyojaae1cwbrvlo192.png'];
return view('/home', [
'images' => $images
]);
}
View page:
@foreach($images as $image)
<div class="img-container">
<a href="#">
<img src="{{ asset( $image ) }}" alt="image">
</a>
</div>
@endforeach
Upvotes: 2