1

I have stored my image with following code

if (isset($image)) {
    // make unique name for image
    $currentDate = Carbon::now()->toDateString();
    $imagename = $slug . '-' . $currentDate . '-' . uniqid() . '.' . $image->getClientOriginalExtension();

    // check category dir is exists
    if (!Storage::disk('public')->exists('category')) {
        Storage::disk('public')->makeDirectory('category');
    }
    // resize image for category and upload
    $category = Image::make($image)->resize(1600,479)->stream();
    Storage::disk('public')->put('category/'.$imagename,$category);
    // check category slider dir is exists
    if (!Storage::disk('public')->exists('category/slider')) {
        Storage::disk('public')->makeDirectory('category/slider');
    }
    // resize image for category slider and upload
    $slider = Image::make($image)->resize(500,333)->stream();
    Storage::disk('public')->put('category/slider/'.$imagename,$slider);
} else {
    $imagename = "default.png";
}

try with this code

<img src="images/icons8-team-355979.jpg" alt="Profile Image">

Failed to load resource: the server responded with a status of 404 (Not Found) this is the error

Yves Kipondo
  • 5,289
  • 1
  • 18
  • 31
Nirob
  • 23
  • 1
  • 9
  • Check -> https://laravel.com/docs/5.7/filesystem#configuration and set link to acces publicly. – Sougata Bose Jan 18 '19 at 09:22
  • Check this https://stackoverflow.com/questions/36066144/how-should-i-serve-an-image-with-laravel/36477345#36477345 – Maytham Fahmi Jan 18 '19 at 09:23
  • You can check here [storage images to access in blade files](https://stackoverflow.com/a/54142037/7478838) this may help you. – jay thanki Jan 18 '19 at 11:31
  • You can check it here [storage images to access in blade files](https://stackoverflow.com/a/54142037/7478838) may this could help you. – jay thanki Jan 18 '19 at 11:33

2 Answers2

1

Try this

<img src="{{url('category/slider')}}/{{ $category->image }}" alt="{{$category->name}}">

The url function will go to '/public' folder. So, you may need to edit your '/config/filesystem.php' so that the uploaded photo is saved inside the '/public' directory.

For more information on this please check this document.

Nabil Farhan
  • 1,444
  • 3
  • 25
  • 41
  • Sorry sir :( I have tried with this code {{ $category->name }} – Nirob Jan 18 '19 at 09:26
  • You don't need to use 'Storage::disk('public')' in blade view. Check my updated answer. – Nabil Farhan Jan 18 '19 at 09:34
  • Check if your picture is saved on '/public/category/slider' directory. Can you please share your 'config/filesystem.php' – Nabil Farhan Jan 18 '19 at 09:56
  • env('FILESYSTEM_DRIVER', 'local'), 'disks' => [ 'local' => ['driver' => 'local','root' => storage_path('app'),], 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'),url' =>env('APP_URL').'/storage','visibility' => 'public', ],'s3' => ['driver' => 's3', 'key' => env('AWS_ACCESS_KEY_ID'), 'secret' => env('AWS_SECRET_ACCESS_KEY'), 'region' => env('AWS_DEFAULT_REGION'), 'bucket' => env('AWS_BUCKET'), 'url' => env('AWS_URL'), ], ], ]; – Nirob Jan 18 '19 at 10:09
  • change 'disks->public->root' from 'storage_path('app/public')' to 'public_path()' – Nabil Farhan Jan 18 '19 at 10:55
0

When you want to serve files from the public disk directly, you need to create a symlink to these files. This is described in the documentation here: https://laravel.com/docs/5.7/filesystem#the-public-disk.

When you have done this, you can link to the assets using the asset() function.

echo asset('category/slider/icons8-team-355979.jpg');
Jerodev
  • 32,252
  • 11
  • 87
  • 108