简体   繁体   English

Laravel Backpack - 在PageTemplate中上传多个

[英]Laravel Backpack - Upload multiple in PageTemplate

I'm trying to upload multiple images on page edit form. 我正在尝试在页面编辑表单上上传多个图像。 In my PageTemplates.php I have: 在我的PageTemplates.php中,我有:

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

In my Page model I have: 在我的Page模型中,我有:

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

    $this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}

In my $disks array in config/filesystems.php I have: config / filesystems.php的 $ disks数组中,我有:

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

But when I try to save the page I have 2 problems: 但是当我尝试保存页面时,我遇到了两个问题:

  • Images aren't saved in folder (folder is writeable!) 图像不保存在文件夹中(文件夹可写!)
  • Not saved in database 未保存在数据库中

In my database extras field for that page I get: 在我的数据库extras字段中,我得到了:

"images":[  
  {  

  },
  {  

  }
],

What am I doing wrong? 我究竟做错了什么?

It worked after doing the following: 执行以下操作后,它工作正常:

  • Add images field to pages table 将图像字段添加到页面表
  • Add 'images' to $fillable in Page model 在“页面模型”中将“图像”添加到$fillable
  • Remove 'fake' => true from PageTemplates.php 从PageTemplates.php中删除'fake' => true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM