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.
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');