Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 !

>Solution :

Try run this command

php artisan storage:link
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading