简体   繁体   中英

laravel5.8:GET 404 (Not Found)

I am using laravel 5.8 and laravel-medialibrary:^7.0.0.

I want to upload my image, and retrieve in profile edit page. But it doesn't work.

In my console, I got an error GET 'my image file' 404 (Not Found) .

This is my code. I used this code after php artisan storage:link

show.blade.php (my profile edit view page)

<img src="{{ asset('storage/'.$channel->image) }}" alt="">

also, I tried

<img src="{{ $channel->image() }}" alt="">

ChannelController.php

public function update(Request $request, Channel $channel)
    {
        if($request->hasFile('image')) {
            $channel->clearMediaCollection('images');
            $channel->addMediaFromRequest('image')
            ->toMediaCollection('images');
        }

        $channel->update([
            'name'=> $request->name,
            'description'=> $request->description
        ]);

        return redirect()->back();
    }

Channel.php

public function registerMediaConversions(?Media $media = null)
    {
        $this->addMediaConversion('thumb')
            ->performOnCollections('images')
            ->width(100)
            ->height(100);
    }

This is my table.

media table 媒体表 channel table 频道表

filesystems.php

 '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'),
        ],

    ],

];

Please use storage_path Laravel function to get the fully qualified path of storage folder. Refer to the link

eg. $filename = storage_path('/imageFolder/photo.jpg');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM