I am trying to retrieve imploded images from the database in Laravel and display it in slides using foreach loop statement.
Stored Images in database colomn
controller
$post= DB::table('posts')->paginate(4); return view('welcome',compact('post'));
view.blade slides
@foreach($post as $posts) <div class="carousel-inner rounded-lg"> <div class="carousel-item active"> <img class="d-block w-100" src="{{asset('admin/upload/images/$posts->image')}}" alt="First slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="{{asset('admin/upload/images/$posts->image')}}" alt="Second slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="{{asset('admin/upload/images/$posts->image')}}" alt="Third slide"> </div> <div class="carousel-item"> <img class="d-block w-100" src="{{asset('admin/upload/images/$posts->image')}}" alt="Fourth slide"> </div> </div>
Advertisement
Answer
You need one more loop :
@foreach(explode("|", $posts->image) as $key => $value) <div class="carousel-item"> <img class="d-block w-100" src="{{ asset('admin/upload/images/' . $value) }}" alt=""> </div> @endforeach