Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theblack68's avatar

cursed Storage

Hi ...Are 2 hour that I try to resolve this problem.

I'm work in local with Homestead and Vagrant and Laraavel 8.x and JETSTREAM (all configured)

I'm try to build a simple application (I want learn good Laravel)

I have 2 simple Model Card and Picture with relative Controller.

All the route are accessible after verification the Email.

I have create a directory pictures in storage with all the images (so is not access from public)

I'm try to return in a view for each card a thumbnail of the image {{ asset('storage/pictures/name.extension) }}

...but nothing not works.

I have do a dd(File::exists(storage_path('pictures/1.jpg'))) => response is true!

In a view I have try also {{ \Illuminate\Support\Facades\Storage::url('immagini/1.jpg') }}

But I can't show in a View ;(

0 likes
3 replies
theblack68's avatar
theblack68
OP
Best Answer
Level 6

I have resolved with return a response in Controller.

I have create a route with some middleware

Route::get('images/{file}', [\App\Http\Controllers\CardController::class, 'getImage'])
    ->middleware(['auth:sanctum', 'verified']);;

And in te controller

/ / Check if file exists
        if (! File::exists(storage_path('immagini/' . $file))){
            abort(404, 'Non sei Autorizzato a visualizzare questa risorsa!');
        }

        $path = storage_path('immagini/' . $file);
        return response()->file($path);

...and finally in a view

<table id="cards" class="display" style="width:100%">
            <thead>
            <tr>
                <th>Titolo</th>
                <th>Anno</th>
                <th>Registro</th>
                <th>Tecnica</th>
                <th>Collezione</th>
                <th>Status</th>
            </tr>
            </thead>
            <tbody>
            @foreach($cards as $card)
            <tr>
                <td>
                    <img src="{{ $card->copertina }}" width="100" />
                    {{ $card->titolo }}
                </td>
                <td>{{ $card->anno }}</td>
                <td>{{ $card->registro }}</td>
                <td>{{ $card->tecnica }}</td>
                <td>{{ $card->collezione_privata }}</td>
                <td>{{ $card->checked }}</td>
            </tr>
            @endforeach
        </table>

Please or to participate in this conversation.