Skip to content
Advertisement

Display all images one by one laravel

On the backend side, my pictures are loaded normally, but I have problems with displaying them on the front

My Model

public function getImageUrl(): ?string
{
  return $this->imageUrl('image');
}

I am trying to display all the images on the page like this

My page.blade.php

<?php
use AppModelsImage;

/**
* @var Image[] $images
*/
?>

<h1>Images</h1>

@foreach($images as $image)
  <img src="{{ $image->getImageUrl() }}">
@endforeach

But I am getting an error: Undefined variable: $images

I need to declare this variable with an array of pictures somewhere on the client side or what to do?

My Controller

public function index(Request $request)
    {
        $images = 

        return view('page', compact('images'));
    }

How can I get all the pictures?

Advertisement

Answer

Here Image is your model name and you need to select all the images so just write done like this model name : all

$image = Image::all();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement