So Repeatable it's an amazing field but i had issue with image field inside it of how to save image path or even override the mutator function of it so after a simple research i was able to fix it like that.
[ // repeatable
'name' => 'images',
'label' => 'Images',
'type' => 'repeatable',
'fields' => [
[
'name' => 'image',
'type' => 'image',
'label' => 'Image'
],
[
'label' => 'Big Image',
'name' => 'is_big',
'type' => 'checkbox',
],
],
]
public function setImagesAttribute($value)
{
$images = json_decode($value, true);
if (count($images)) {
foreach ($images as &$jsonInfo) {
$image = $jsonInfo['image'];
if (Str::startsWith($image, 'data:image')) {
$newImage = $this->setImageMutator($image);
$jsonInfo['image'] = $newImage;
}
}
$this->attributes['images'] = json_encode($images);
}
}
public function setImageMutator($value) {
// or use your own disk, defined in config/filesystems.php
$disk = 'cloud_disk';
// destination path relative to the disk above
$destination_path = "cloud/media/uploads";
// if the image was erased
// if ($value==null) {
// // delete the image from disk
// \Storage::disk($disk)->delete($this->{$attribute_name});
//
// // set null in the database column
// $this->attributes[$attribute_name] = null;
// }
// if a base64 was sent, store it in the db
if (Str::startsWith($value, 'data:image'))
{
// 0. Make the image
$image = \Intervention\Image\Facades\Image::make($value)->encode('jpg', 90);
// 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. Delete the previous image, if there was one.
// \Storage::disk($disk)->delete($this->{$attribute_name});
// 4. Save the public path to the database
// but first, remove "public/" from the path, since we're pointing to it
// from the root folder; that way, what gets saved in the db
// is the public URL (everything that comes after the domain name)
$public_destination_path = Str::replaceFirst('public/', '', $destination_path);
return $public_destination_path.'/'.$filename;
}
}
Hope it helps someone and hope it make sense, any suggests for improvements.