From fe653f44945fd295787d3a206195d8eabf5d744f Mon Sep 17 00:00:00 2001
From: Ash Monsh
Date: Wed, 12 Jul 2023 08:41:15 +0300
Subject: [PATCH 1/2] allow to upload multiple libraries and refactor the views
---
.../themes/zeus/addons/library-item.blade.php | 23 ++++---------------
.../zeus/addons/library-types/file.blade.php | 3 +++
.../zeus/addons/library-types/image.blade.php | 3 +++
.../zeus/addons/library-types/video.blade.php | 4 ++++
src/Filament/Resources/LibraryResource.php | 2 ++
src/Models/Library.php | 12 +++++++++-
6 files changed, 28 insertions(+), 19 deletions(-)
create mode 100644 resources/views/themes/zeus/addons/library-types/file.blade.php
create mode 100644 resources/views/themes/zeus/addons/library-types/image.blade.php
create mode 100644 resources/views/themes/zeus/addons/library-types/video.blade.php
diff --git a/resources/views/themes/zeus/addons/library-item.blade.php b/resources/views/themes/zeus/addons/library-item.blade.php
index 713cf48..68a82ec 100644
--- a/resources/views/themes/zeus/addons/library-item.blade.php
+++ b/resources/views/themes/zeus/addons/library-item.blade.php
@@ -27,23 +27,10 @@
{{ $item->created_at->format('Y.m/d') }}-{{ $item->created_at->format('h:i a') }}
- @if($item->type === 'IMAGE')
-
- @endif
-
- @if($item->type === 'FILE')
-
-
- {{ __('Show File') }}
-
-
- @endif
-
- @if($item->type === 'VIDEO')
-
- @endif
+
+ @foreach($item->getFiles() as $file)
+ @include($theme.'.addons.library-types.'.strtolower($item->type))
+ @endforeach
+
diff --git a/resources/views/themes/zeus/addons/library-types/file.blade.php b/resources/views/themes/zeus/addons/library-types/file.blade.php
new file mode 100644
index 0000000..2fd8004
--- /dev/null
+++ b/resources/views/themes/zeus/addons/library-types/file.blade.php
@@ -0,0 +1,3 @@
+
+ {{ __('Show File') }}
+
\ No newline at end of file
diff --git a/resources/views/themes/zeus/addons/library-types/image.blade.php b/resources/views/themes/zeus/addons/library-types/image.blade.php
new file mode 100644
index 0000000..7f84e9d
--- /dev/null
+++ b/resources/views/themes/zeus/addons/library-types/image.blade.php
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/resources/views/themes/zeus/addons/library-types/video.blade.php b/resources/views/themes/zeus/addons/library-types/video.blade.php
new file mode 100644
index 0000000..3bc02ca
--- /dev/null
+++ b/resources/views/themes/zeus/addons/library-types/video.blade.php
@@ -0,0 +1,4 @@
+
\ No newline at end of file
diff --git a/src/Filament/Resources/LibraryResource.php b/src/Filament/Resources/LibraryResource.php
index 9f91d26..97a54d4 100644
--- a/src/Filament/Resources/LibraryResource.php
+++ b/src/Filament/Resources/LibraryResource.php
@@ -95,6 +95,8 @@ public static function form(Form $form): Form
SpatieMediaLibraryFileUpload::make('file_path_upload')
->collection('library')
+ ->multiple()
+ ->enableReordering()
->visible(fn (Closure $get) => $get('upload_or_url') === 'upload')
->label(''),
diff --git a/src/Models/Library.php b/src/Models/Library.php
index a28ea1f..d11ea63 100644
--- a/src/Models/Library.php
+++ b/src/Models/Library.php
@@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
+use Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection;
use Spatie\Tags\HasTags;
use Spatie\Translatable\HasTranslations;
@@ -48,7 +49,7 @@ public function getRouteKeyName()
return 'slug';
}
- public function theFile()
+ public function theFile(): ?string
{
if (! $this->getMedia('library')->isEmpty()) {
return $this->getFirstMediaUrl('library');
@@ -56,4 +57,13 @@ public function theFile()
return $this->file_path;
}
+
+ public function getFiles(): ?MediaCollection
+ {
+ if (! $this->getMedia('library')->isEmpty()) {
+ return $this->getMedia('library');
+ }
+
+ return null;
+ }
}
From cadcce520180d3852aa4656f4c096d8f208cf419 Mon Sep 17 00:00:00 2001
From: atmonshi
Date: Wed, 12 Jul 2023 05:42:12 +0000
Subject: [PATCH 2/2] Fix styling
---
src/Http/Livewire/SearchHelpers.php | 2 +-
src/Models/Tag.php | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Http/Livewire/SearchHelpers.php b/src/Http/Livewire/SearchHelpers.php
index b205c0d..3ff78a9 100644
--- a/src/Http/Livewire/SearchHelpers.php
+++ b/src/Http/Livewire/SearchHelpers.php
@@ -6,7 +6,7 @@
trait SearchHelpers
{
- private function highlightSearchResults(Collection $collection, ?string $search = null): Collection
+ private function highlightSearchResults(Collection $collection, string $search = null): Collection
{
if (! $search) {
return $collection;
diff --git a/src/Models/Tag.php b/src/Models/Tag.php
index 64a4267..995131b 100644
--- a/src/Models/Tag.php
+++ b/src/Models/Tag.php
@@ -55,7 +55,7 @@ protected function generateSlug(string $locale): string
return call_user_func($slugger, $this->getTranslation('name', $locale));
}
- public static function findBySlug(string $slug, string $type = null, string $locale = null): Model|null
+ public static function findBySlug(string $slug, string $type = null, string $locale = null): ?Model
{
$locale = $locale ?? static::getLocale();