在 Laravel 8 中使用 spatie 媒体库未显示图像
images not showing using spatie media library in Laravel 8
我无法显示使用 spatie 媒体库上传的图像。我已经查看了他们的文档,但找不到解决方案。
我上传文件没有问题(仅限单个文件)。
数据库媒体Table
控制器@商店
public function store(Request $request)
{
$categories = new ProductCategories();
$categories->name = $request->name;
$categories->slug = $request->slug;
$categories->description = $request->description;
if($request->hasFile('photo') && $request->file('photo')->isValid()){
$categories->addMediaFromRequest('photo')->toMediaCollection('category');
}
$categories->save();
$request->session()->flash('message', 'Successfully created category');
return redirect()->back();
}
控制器@索引
public function index()
{
$lists = ProductCategories::all();
return view('dashboard\product_category\categoryList', [ 'lists' => $lists ]);
}
config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => public_path('images/media'),
'url' => env('APP_URL').'/images/media',
'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'),
],
],
config/media-library.php
'disk_name' => env('MEDIA_DISK', 'public'),
这些是我的媒体文件夹:
wamp64/www/butingting/public/images/media/2
wamp64/www/butingting/public/images/media/3
wamp64/www/butingting/public/images/media/4
Blade 页
@foreach ($lists as $list)
<tr>
<td>
<img src="{{$list->getFirstMediaUrl('category')}}" width="120px"><br/>
{{$list->getFirstMediaUrl('category')}}
</td>
</tr>
@endforeach
如果我加上{{$list->getFirstMediaUrl('category')}}
,它看起来像这样:
我已经完成了“php artisan storage:link”
有什么建议吗?
感谢 Lulzash 和 Mtxz 的宝贵时间!我检查并长时间盯着 env 文件 :( 特别是在 APP_URL.
解决方案是:
形式 APP_URL=localhost:8000 或 APP_URL=https://localhost:8000
应该是APP_URL=http://localhost:8000
谢谢 Mtxz 因为你的问题让我决定重新考虑 APP_URL!
我无法显示使用 spatie 媒体库上传的图像。我已经查看了他们的文档,但找不到解决方案。
我上传文件没有问题(仅限单个文件)。
数据库媒体Table
控制器@商店
public function store(Request $request)
{
$categories = new ProductCategories();
$categories->name = $request->name;
$categories->slug = $request->slug;
$categories->description = $request->description;
if($request->hasFile('photo') && $request->file('photo')->isValid()){
$categories->addMediaFromRequest('photo')->toMediaCollection('category');
}
$categories->save();
$request->session()->flash('message', 'Successfully created category');
return redirect()->back();
}
控制器@索引
public function index()
{
$lists = ProductCategories::all();
return view('dashboard\product_category\categoryList', [ 'lists' => $lists ]);
}
config/filesystems.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => public_path('images/media'),
'url' => env('APP_URL').'/images/media',
'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'),
],
],
config/media-library.php
'disk_name' => env('MEDIA_DISK', 'public'),
这些是我的媒体文件夹:
wamp64/www/butingting/public/images/media/2
wamp64/www/butingting/public/images/media/3
wamp64/www/butingting/public/images/media/4
Blade 页
@foreach ($lists as $list)
<tr>
<td>
<img src="{{$list->getFirstMediaUrl('category')}}" width="120px"><br/>
{{$list->getFirstMediaUrl('category')}}
</td>
</tr>
@endforeach
如果我加上{{$list->getFirstMediaUrl('category')}}
,它看起来像这样:
我已经完成了“php artisan storage:link”
有什么建议吗?
感谢 Lulzash 和 Mtxz 的宝贵时间!我检查并长时间盯着 env 文件 :( 特别是在 APP_URL.
解决方案是:
形式 APP_URL=localhost:8000 或 APP_URL=https://localhost:8000
应该是APP_URL=http://localhost:8000
谢谢 Mtxz 因为你的问题让我决定重新考虑 APP_URL!