Storage::Delete 路径位置未被覆盖

Storage::Delete path location not overridden

[在此处输入图片描述][1]不是这样吗?但它并没有删除图像,尽管它存储了图像

如果不是这样,我该如何覆盖 public 中的路径 控制器?

已编辑(按照建议):我在 filesystem.php 中添加了新磁盘 "public",并通过添加 Storage facade 修改了控制器。


在我的 controller.php

public function update(Request $request, $userId)
{
    $oldFileName='';
    $filenameToStore='';
    //saving the user
    $user=User::find($userId);
    $user->first_name = $request->input('first_name');

    //for the image
    if ($request->hasFile('user_image')) {
        $image = $request->file('user_image');

        //get filename
        $filenameToStore= $image->getClientOriginalName();

       $location = public_path('chbea/users/images/' .$filenameToStore);

        Image::make($image)->save($location);
        $oldFileName =$user->user_image;

        Storage::disk('public')->delete('chbea/users/images/'. 
        $oldFileName);

        //saving user image name
        $user->user_image = $filenameToStore;
    }

    $user->save();
    Session::flash('success', 'The Student Details was Updated!');
    return redirect()->route('students.index');


}

在我的 filesystems.php

<?php

return [


'default' => env('FILESYSTEM_DRIVER', 'local'),


'cloud' => env('FILESYSTEM_CLOUD', 's3'),


'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => public_path('images/'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => public_path(),
    ],

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

  ],

 ];

当我添加输出时,路径不是预期的路径。

dd(Storage::disk('public'), 
  Storage::disk('public')>path('chbea/users/images/'.$oldFileName),
  Storage::disk('public')->exists('chbea/users/images/'.$oldFileName)
 [enter image description here][1]);

这是输出 https://i.stack.imgur.com/euVWR.png

所以这里的问题是,当您像在 filesystems.php 配置中那样设置文件系统时,它 jails 该文件系统到您定义的路径。因此,在您的情况下,您的 local 文件系统被监禁到 public_path('allimages/')。您不能使用该磁盘超出该文件系统。

不过您可以创建另一个磁盘,将其固定在不同的位置:

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => public_path('allimages/'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => public_path()
    ],

我在这里创建了另一个名为 public 的磁盘并将该磁盘放入 public 路径。然后你可以像这样使用存储门面:

Storage::disk('public')->delete('project/users/images/' . $oldFileName);

这将删除由您指定的相对于 public 磁盘根目录的路径所标识的文件。

所以这终于解决了......

$oldFileName =$user->user_image;  
Storage::disk('customDisk')->delete('chbea/users/images/' . $oldFileName);

在我的 filesystems.php

 'customDisk' => [
        'driver' => 'local',
        'root' => public_path(),
 ],

最重要的是 运行 这个命令,否则你会得到驱动程序不支持的错误

  php artisan config:cache