Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Backpack - Upload multiple in PageTemplate

I'm trying to upload multiple images on 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 $disks 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 aren't saved in folder (folder is writeable!)
  • Not saved in database

In my database extras field for that page I get:

"images":[  
  {  

  },
  {  

  }
],

What am I doing wrong?

like image 538
nielsv Avatar asked Oct 29 '22 23:10

nielsv


1 Answers

It worked after doing the following:

  • Add images field to pages table
  • Add 'images' to $fillable in Page model
  • Remove 'fake' => true from PageTemplates.php
like image 122
nielsv Avatar answered Nov 01 '22 20:11

nielsv