0

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 !

1
  • Usually, we upload it to public. public_path('uploads') Commented Sep 13, 2022 at 11:28

3 Answers 3

2

Try run this command

php artisan storage:link
Sign up to request clarification or add additional context in comments.

2 Comments

I have the same problem :/
Link exists but I don't have the image
0

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

replace

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

with

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

1 Comment

Please use code highlighting in you answer and also, please add some more information why this change should fix the problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.