From a6e77dd46fa18f191d5918de969c17153aae4582 Mon Sep 17 00:00:00 2001 From: Pharaonic <73609630+Pharaonic@users.noreply.github.com> Date: Thu, 26 Nov 2020 09:38:55 +0200 Subject: [PATCH] on Create --- src/HasImages.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/HasImages.php b/src/HasImages.php index 6ad4aba..05412c7 100644 --- a/src/HasImages.php +++ b/src/HasImages.php @@ -21,6 +21,15 @@ trait HasImages */ protected static $imagesItems = []; + + /** + * @return void + */ + public function initializeHasImages() + { + $this->fillable[] = 'images'; + } + protected static function bootHasImages() { // Created @@ -65,11 +74,11 @@ protected static function bootHasImages() public function _setImagesAttribute($images) { $this->clearImages(); - + $options = $this->filesOptions['images'] ?? []; foreach ($images as $sort => $img) { $this->images()->create([ 'sort' => $sort, - 'upload_id' => upload($img)->id + 'upload_id' => upload($img, $options)->id ]); } @@ -78,9 +87,10 @@ public function _setImagesAttribute($images) public function addImage(UploadedFile $img, int $sort = 0) { + $options = $this->filesOptions['images'] ?? []; return $this->images()->create([ 'sort' => $sort, - 'upload_id' => upload($img)->id + 'upload_id' => upload($img, $options)->id ]); }