Caroline Dorchies
Caroline Dorchies

Reputation: 27

Laravel 9 - Upload Image - Image does not display

I'm creating a shop, with an upload image in Laravel 9.

Everything is on my database, and my image is sent on file storage/app/public/nameofthefile/nameoftheimage.png.

But my image does not appear on my website like this :

enter image description here

As you can see on the console, the image has the correct direction I give you the code of my controller, my html page :

My CONTROLLER :

    public function CreateArticleAction(Request $request) {

    $request->validate([
        'nom' => ['required'],
        'description' => ['required'],
        'prix' => ['required'],
        'quantité' => ['required'],
        'img' => ["required", "image", "mimes:jpg,jpeg,png,gif,svg,webp", "max:2048"],
    ]);

    $path = $request->file('img')->store('boutique-storage', 'public');
    $iduser = Session::get('iduser');

    $article = new Boutique();
    $article->iduser = $iduser;
    $article->nom = request('nom');
    $article->description = request('description');
    $article->prix = request('prix');
    $article->quantité = request('quantité');
    $article->img = $path;
    $article->save();

    return redirect('/boutique');
}

My HTML page :

            @foreach ($boutiques as $boutique)
            <div class="produit">
                <img src="{{ asset('storage/app/public/' . $boutique->img) }}" alt="Produit" class="img-produit" />
                <p>{{ $boutique->nom }}</p>
                <p>{{ $boutique->description }}</p>
                <p>{{ $boutique->prix }}</p>
                <p>{{ $boutique->quantité }}</p>
                <div>
                    <a class="text-danger" href="/delete-article/{{ $boutique->idproduit }}">Supprimer</a>
                    <a class="text-primary" href="/FormUpdate/{{ $boutique->idproduit }}">Modifier</a>
                </div>
            </div>
        @endforeach

And the DIRECTION :

enter image description here

I think you can see everything is ok, each data is sent correctly on the database but why my image does not appear ??

Thanks a lot !

Upvotes: 0

Views: 2692

Answers (3)

babita
babita

Reputation: 33

replace

<img src="{{ asset('storage/app/public/' . $boutique->img) }}"

with

<img src="{{ asset($boutique->img) }}"

Upvotes: 0

Caroline Dorchies
Caroline Dorchies

Reputation: 27

Ah ok so I forgot to add this on .env file : FILESYSTEM_DISK=public

Now with the command php artisan storage:link it works :D

Upvotes: 0

Ahmed Saad
Ahmed Saad

Reputation: 144

Try run this command

php artisan storage:link

Upvotes: 2

Related Questions