I'm using backpackforlaravel to set up the backend area of my website. I've added an image field in my ProjectCrudController:

$this->crud->addField([
    'label' => "Project Image",
    'name' => "image",
    'type' => 'image',
    'upload' => true,
], 'both');

在我的Project型车中,我有这样一个mutator:

public function setImageAttribute($value)
{
    $attribute_name = "image";
    $disk = "public_folder";
    $destination_path = "uploads/images";

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

        // 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);
        // 1. Generate a filename.
        $filename = md5($value.time()).'.jpg';

        // 2. Store the image on disk.
        \Storage::disk($disk)->put($destination_path.'/'.$filename, $image->stream());
        // 3. Save the path to the database
        $this->attributes[$attribute_name] = $destination_path.'/'.$filename;
    }
}

In my public folder I have /uploads/images/ folder.

但是,当我想要保存项目时,我会收到以下错误:

InvalidArgumentException in FilesystemManager.php line 121:

不支持驱动程序[].

enter image description here

My filesystems.php file in my config folder looks like this:

<?php

return [

    'default' => 'local',

    'cloud' => 's3',

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
        ],
        'uploads' => [
            'driver' => 'local',
            'root' => public_path('uploads'),
        ],

    ],

    'storage' => [
        'driver' => 'local',
        'root'   => storage_path(),
    ],

];

What could be the problem here? I'm using Laravel Homestead version 2.2.2.

推荐答案

Here you defined the $disk as public_folder:

public function setImageAttribute($value)
{
    $attribute_name = "image";
    $disk = "public_folder";
    $destination_path = "uploads/images";

But in your filesystem.php you don't have the public_folder disk

You need to create a new "public_folder" disk

'disks' => [

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

or rename your $disk variable to another disk:

public function setImageAttribute($value)
{
    $attribute_name = "image";
    //Uploads disk for example
    $disk = "uploads";

Laravel相关问答推荐

Laravel模型嵌入嵌套模型时只附加属性

子目录中具有Vue实例的Laravel不起作用

LaravelEloquent 的模型如何将值从控制器内部的函数传递到Render()

Laravel 联合和分页

Laravel 语法 GroupBy 获取列到数组

如何获取多态多对多关系子查询的自动 id 列名?

我在 laravel 中插入多个复选框值.我怎样才能做到这一点?

如何在 Laravel Eloquent Collection 数组之前添加一个键值对?

将 Laravel 升级到 4.2 后,Artisan::call('migrate') 不起作用

Laravel 中间件返回(try 获取非对象的属性 headers)错误

如何仅从 laravel FormRequest 中获取经过验证的数据?

如何在 AWS Elastic Beanstalk 上设置和使用 Laravel 调度?

Laravel Passport 通过访问令牌获取客户端 ID

在 Laravel 5 控制器中找不到类App\Http\Controllers\DB

Laravel homestead IP地址不起作用

如何在 Laravel 中显示动态复选框的旧数据?

同一模型上的 Laravel 父/子关系

Laravel 5 Illuminate\Http\Request 的方法不允许静态调用

使用 Carbon 将小时转换为 PM 和 AM

在 Laravel 中翻译特定语言