Laravel Backpack - 在PageTemplate中上传多个

nie*_*lsv 5 php upload laravel laravel-5 backpack-for-laravel

我正在尝试在页面编辑表单上上传多个图像.在我的PageTemplates.php中,我有:

$this->crud->addField([ 
    'name' => 'images',
    'label' => 'Fotos',
    'type' => 'upload_multiple',
    'upload' => true,
    'disk' => 'uploads',
    'hint' => 'Some hint text.',
    'fake' => true
]);
Run Code Online (Sandbox Code Playgroud)

在我的Page模型中,我有:

public function setImagessAttribute($value)
{
    $attribute_name = "images";
    $disk = "uploads";
    $destination_path = "images/pages";

    $this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}
Run Code Online (Sandbox Code Playgroud)

config/filesystems.php的$ disks数组中,我有:

'uploads' => [
    'driver' => 'local',
    'root' => public_path('uploads'),
],
Run Code Online (Sandbox Code Playgroud)

但是当我尝试保存页面时,我遇到了两个问题:

  • 图像不保存在文件夹中(文件夹可写!)
  • 未保存在数据库中

在我的数据库extras字段中,我得到了:

"images":[  
  {  

  },
  {  

  }
],
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

nie*_*lsv 2

执行以下操作后它起作用了:

  • 将图像字段添加到页面表中
  • 添加“图像”至$fillable页面模型中
  • 'fake' => true从 PageTemplates.php 中删除