在我的 laravel 项目中,我试图在表格中显示博客文章标题和图像。帖子的图像被上传并存储在公共(public)/存储中。 这是我用来存储有效图像的代码
$image = $request->image->store('posts');
在index.blade.php中我使用此代码来显示帖子
图像 标题 <tbody>
@foreach ($posts as $post )
<tr>
<td>
<img src="{{ asset($post->image) }}" width="120px" height="60px" alt="">
</td>
<td>
{{$post->title}}
</td>
</tr>
@endforeach
</tbody>
</table>
前端图像出现损坏,我似乎无法修复该问题 This is how it shows
我已经成功执行了 php artisan storage:link
但仍然没有结果。
我已将这行代码添加到 .env 文件中 FILESYSTEM_DRIVER=public
如果这很重要的话,这就是我的 filesystems.php 文件的样子
<?php
返回[
/*
|--------------------------------------------------------------------------
| Default Filesystem Disk
|--------------------------------------------------------------------------
|
| Here you may specify the default filesystem disk that should be used
| by the framework. The "local" disk, as well as a variety of cloud
| based disks are available to your application. Just store away!
|
*/
'default' => env('FILESYSTEM_DRIVER', 'local'),
/*
|--------------------------------------------------------------------------
| Default Cloud Filesystem Disk
|--------------------------------------------------------------------------
|
| Many applications store files both locally and in the cloud. For this
| reason, you may specify a default "cloud" driver here. This driver
| will be bound as the Cloud disk implementation in the container.
|
*/
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
/*
|--------------------------------------------------------------------------
| Filesystem Disks
|--------------------------------------------------------------------------
|
| Here you may configure as many filesystem "disks" as you wish, and you
| may even configure multiple disks of the same driver. Defaults have
| been setup for each driver as an example of the required options.
|
| Supported Drivers: "local", "ftp", "sftp", "s3"
|
*/
'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'),
'endpoint' => env('AWS_ENDPOINT'),
],
],
/*
|--------------------------------------------------------------------------
| Symbolic Links
|--------------------------------------------------------------------------
|
| Here you may configure the symbolic links that will be created when the
| `storage:link` Artisan command is executed. The array keys should be
| the locations of the links and the values should be their targets.
|
*/
'links' => [
public_path('storage') => storage_path('app/public'),
],
];
有谁知道为什么会发生这种情况,我的代码中是否存在我没有看到的错误?
最佳答案
试试这个,
<img src="{{ Storage::url($post->image) }}" width="120px" height="60px" alt="">
关于php - 图像未显示在前端。拉维尔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67019487/