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 App\Models\Image;

/**
* @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?

>Solution :

Here Image is your model name and you need to select all the images

$image = Image::all();

Leave a Reply