Laravel 5 不从laravel背包4.0中删除图像

Laravel 5 不从laravel背包4.0中删除图像,laravel-5,laravel-backpack,Laravel 5,Laravel Backpack,我正在使用laravel背包4.0中的图像字段,它可以毫无问题地上传图像。当我使用删除按钮删除图像时,它会删除寄存器(E.N.可能意味着“从数据库中删除图像”),但不会删除本地文件夹中的图像文件。我已经检查了来自的答案,但这无助于解决我的问题 我的配置/文件系统: 'disks' => [ 'local' => [ 'driver' => 'local', 'root' => storage_path('app'), ],

我正在使用laravel背包4.0中的图像字段,它可以毫无问题地上传图像。当我使用
删除按钮
删除图像时,它会删除寄存器(E.N.可能意味着“从数据库中删除图像”),但不会删除本地文件夹中的图像文件。我已经检查了来自的答案,但这无助于解决我的问题

我的配置/文件系统:

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

],
我的型号代码:

public function setImageAttribute($value)
{
    $attribute_name = "image";
    $disk = config('backpack.base.root_disk_name'); // or use your own disk, defined in config/filesystems.php
    $destination_path = env('FOLDER_PUBLIC')."/uploads/medias"; // path relative to the disk above

    // if the image was erased
    if ($value==null) {
        // delete the image from disk
        \Storage::disk($disk)->delete($this->{$attribute_name});

        // set null in the database column
        $this->attributes[$attribute_name] = null;
    }

    // if a base64 was sent, store it in the db
    if (starts_with($value, 'data:image'))
    {
        // 0. Make the image
        $image = \Image::make($value)->encode('jpg', 90);
        // 1. Generate a filename.
        $filename = rand ( 10000 , 99999 ).'-'.strtolower(trim(preg_replace('/[\s-]+/', '-', preg_replace('/[^A-Za-z0-9-]+/', '-', preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $this->title))))), '-')).'.jpg';

        // 2. Store the image on disk.
        \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
        // 3. Save the public path to the database
        // but first, remove "public/" from the path, since we're pointing to it from the root folder
        // that way, what gets saved in the database is the user-accesible URL
        $public_destination_path = Str::replaceFirst(env('FOLDER_PUBLIC').'/', '', $destination_path);
        $this->attributes[$attribute_name] = $public_destination_path.'/'.$filename;
    }
}
public static function boot()
{
    parent::boot();

    static::deleting(function($obj) {

        \Storage::disk('public')->delete($obj->image);
    });
}
我试图改变:

\Storage::disk('public')->delete($obj->image);
与:

但它也不起作用

有人能帮我吗


对不起,我说的是英语,你说得对。如果
boot()
中的代码不影响任何更改,则可能是配置错误。我的猜测是,您试图删除的文件的
$obj->image
路径不是该文件的确切路径。您可能还需要在那里添加目标文件夹


公共静态函数boot()
{
父::boot();
静态::删除(函数($obj){
$disk=config('backpack.base.root_disk_name');
$destination_path=env('FOLDER_PUBLIC')。“/uploads/medias”;
\存储::磁盘($disk)->删除($destination_path.'/'.$this->image);
});
}

如果这样做有效,为了进一步改进代码,我建议您将
$disk
$destination\u path
变量转换为PHP类本身(Laravel模型)的属性。这样,您只需在一个位置定义它们,然后就可以在两种方法中使用它们,使用类似于
$this->imageDisk
$this->imagePath
的方法。谢谢您的回复,最后我已经修复了它,进行了以下更改:

 public static function boot()
{
    parent::boot();

    static::deleting(function($obj) {

        \Storage::disk('uploads')->delete($obj->image);
    });
}
在config/filesystem中:

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

],
“磁盘”=>[

    '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'),
    ],
    'uploads' => [
        'driver' => 'local',
       /* 'root'   => base_path().'/web/storage',*/
        'root'   => base_path().'/'.env('FOLDER_PUBLIC'),
    ],

],
问候