本地主机 Laravel 8 中的存储链接问题

Storage Linking Issue in Laravel 8 on localhost

描述:

我正在使用此代码 laravel 上传图片:

$product_image = $request->file('product_image');
$product_image_extension = $product_image->extension();
$product_image_name = time() . '.' . $product_image_extension;
$product_image->storeAs('/media/product_images', $product_image_name);
$model->product_image = $product_image_name;

没问题,文件上传到storage/app/media/product_images/.

然后,我运行命令

php artisan storage: link

在 public 中创建符号链接。 命令执行如下:

Local NTFS volumes are required to complete the operation.
The [E:\Complete Programming Bootcamp\laravel Work\ecom-project\cyber_shopping\public\storage] link 
has been connected to [E:\Complete Programming Bootcamp\laravel Work\ecom- 
project\cyber_shopping\storage\app/public].
The links have been created.

我正在使用此代码显示图像:

{{asset('storage/media/product_images/' . $list->product_image)}}

但是前端没有显示图片。

此外,public 文件夹中未创建存储文件夹。 PLz,帮帮我。

谢谢

步骤 1:: 存​​储图像

$path = ‘’;
if( $request->has('product_image') ) {
    $path = $request->file('product_image')->store('media/product_images');
}
$model->product_image = $path;

步骤 2:: 检查存储文件路径

文件将存储在路径::

————————————————————————————————

Storage/app/public/media/product_images/

步骤 3:: Link 存储在 Public 文件夹中

运行 存储 Link 命令并从 public 中删除存储 link 文件夹(如果已经存在)

php artisan storage:link

步骤 4:: 创建全局函数以访问图像主文件 Controller.php 文件创建全局存储图像获取函数如下所示

public static function getUrl($path)
{
    $url = "";
    if( !empty($path) && Storage::disk('public')->exists($path) )
        $url = Storage::url($path);
    return $url;
}

第 5 步::使用 Assest 中的函数显示图像

<img src="{{ getUrl($list->product_image) }}" />

根据 https://github.com/photoncms/cms/issues/8,您正在尝试在 fat32 驱动器上进行符号链接,但它无法在该驱动器上运行。尝试在 NTFS 驱动器上测试它