Skip to content

Commit

Permalink
on Create
Browse files Browse the repository at this point in the history
  • Loading branch information
Pharaonic committed Nov 26, 2020
1 parent 42d7b10 commit a6e77dd
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/HasImages.php
Expand Up @@ -21,6 +21,15 @@ trait HasImages
*/
protected static $imagesItems = [];


/**
* @return void
*/
public function initializeHasImages()
{
$this->fillable[] = 'images';
}

protected static function bootHasImages()
{
// Created
Expand Down Expand Up @@ -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
]);
}

Expand All @@ -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
]);
}

Expand Down

0 comments on commit a6e77dd

Please sign in to comment.