Laravel Backpack - Loading Multiple in PageTemplate

I am trying to upload multiple images to a page edit form. In my PageTemplates.php , I have:

$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:

 public function setImagessAttribute($value) { $attribute_name = "images"; $disk = "uploads"; $destination_path = "images/pages"; $this->uploadMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path); } 

In my $ drive array in config / filesystems.php I have:

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

But when I try to save the page, I have 2 problems:

  • Images are not saved in the folder (the folder is writable!)
  • Not saved to database

In my database, the field of additional functions for this page I get:

 "images":[ { }, { } ], 

What am I doing wrong?

+5
source share
1 answer

It worked after doing the following:

  • Add image to page table
  • Add 'images' to $fillable in page model
  • Remove 'fake' => true from PageTemplates.php
+2
source

Source: https://habr.com/ru/post/1273488/


All Articles