Skip to content

Commit

Permalink
fix gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed May 2, 2024
1 parent 136165f commit 3d5740a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/Http/Resources/Project/ShowProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public function toArray(Request $request): array
return [
'src' => $media->getFullUrl(),
'thumbnail' => $media->getFullUrl('preview'),
'width' => $media->getCustomProperty('width') ?? '100%',
'height' => $media->getCustomProperty('height') ?? '100%',
];
})->toArray(),
'is_active' => $this->is_active,
Expand Down
11 changes: 9 additions & 2 deletions app/Services/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ private static function updateGallery(Project $project, ?array $value): void
$media->delete();
}
});

collect($value)->filter(fn ($image) => ! \is_array($image))
->map(fn ($image) => $project->addMedia($image)->toMediaCollection('gallery'));
->map(function ($image) use ($project) {
$tmpImage = Image::load($image->getPathname());

$width = $tmpImage->getWidth();
$height = $tmpImage->getHeight();
$project->addMedia($image)
->withCustomProperties($width || $height ? compact('width', 'height') : [])
->toMediaCollection('gallery');
});
}

public function create(array $data): Project|GalaProject
Expand Down
1 change: 1 addition & 0 deletions resources/js/Components/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
rel="noreferrer"
>
<img :src="image.thumbnail" alt="" />
{{ image }}
</a>
</div>
</template>
Expand Down

0 comments on commit 3d5740a

Please sign in to comment.