John Davidson

php - LARAVEL7 uploading image but not showing in page

0 comments
Message:


I'm trying to upload an image for every product with a normal crud form


with this code i can see that i upload the images in storage>app>uploads


i can see in phpMyAdmin that the same name i see in VScode (example 185138_1616528993.png )
is showing there but i get broken image in browser. i dont know what to do anymore


This is the store function


        $newProduct = Product::make($request -> all());
$color = Color::findOrFail($request['color_id']);

$img = $request -> file('imgpro');

$ext = $img -> getClientOriginalExtension();
$name = rand(100000, 999999) . '_' . time();
$fileName = $name . '.' . $ext;

$img -> storeAs('uploads/', $fileName);
$newProduct -> imgpro = $fileName;

$newProduct -> color() -> associate($color);

$newProduct -> save();
return redirect() -> route('product-show', $newProduct -> id);// route('product-index');




return redirect() -> route('product-show', $newProduct -> id);// route('product-index');

this is the product-show.blade.php


    <img src="{{ asset('/public/uploads/' . $product -> imgpro) }}"  alt="imgpro">

<img src="{{ asset('/storage/app/uploads/' . $product->imgpro) }}" alt="imgpro2">

<img src="{{ asset( $product -> imgpro )}}" alt="imgpro3">

<img src="{{ $product -> imgpro }}" alt="boh">


i did the phpartisan storage



My Answer:
It looks like you are storing the image in the `uploads` directory inside the `storage/app` directory. However, when you are trying to display the image in your `product-show.blade.php` file, you are using incorrect paths.

Here are a few things you can try:

1. Update the image path in your `product-show.blade.php` file to point to the correct directory where the image is stored. Since you are storing the image in the `uploads` directory inside `storage/app`, you can use the following code:

html
imgpro


2. Make sure that you have created a symbolic link from the `public/storage` directory to the `storage/app/public` directory. You can create the symbolic link by running the following command:

bash
php artisan storage:link


3. After creating the symbolic link, you should be able to access the image using the `storage` disk. Make sure that the `APP_URL` in your `.env` file is set correctly.

By following these steps, you should be able to display the uploaded image in your page. Let me know if you encounter any issues.

Rate this post

4 of 5 based on 8158 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us