Skip to content

Commit 66915b3

Browse files
committed
Generate infolists
1 parent bceb379 commit 66915b3

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,15 @@ You must also [prepare your Eloquent model](https://spatie.be/docs/laravel-media
2626
2727
## Form component
2828

29-
You may use the field in the same way as the [original file upload](https://filamentphp.com/docs/forms/fields/file-upload) field:
29+
You may use the field in the same way as the [original file upload](https://filamentphp.com/docs/forms/file-upload) field:
3030

3131
```php
3232
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
3333

3434
SpatieMediaLibraryFileUpload::make('avatar')
3535
```
3636

37-
The media library file upload supports all the customization options of the [original file upload component](https://filamentphp.com/docs/forms/fields/file-upload).
38-
39-
> The field will automatically load and save its uploads to your model. To set this functionality up, **you must also follow the instructions set out in the [setting a form model](https://filamentphp.com/docs/forms/adding-a-form-to-a-livewire-component#setting-a-form-model) section**. If you're using a [panel](../panels), you can skip this step.
37+
The media library file upload supports all the customization options of the [original file upload component](https://filamentphp.com/docs/forms/file-upload).
4038

4139
### Passing a collection
4240

@@ -51,7 +49,7 @@ SpatieMediaLibraryFileUpload::make('avatar')
5149

5250
### Configuring the storage disk and directory
5351

54-
By default, files will be uploaded publicly to your storage disk defined in the [Filament configuration file](https://filamentphp.com/docs/forms/installation#publishing-configuration). You can also set the `FILAMENT_FILESYSTEM_DISK` environment variable to change this. This is to ensure consistency between all Filament packages. Spatie's disk configuration will not be used, unless you [define a disk for a registered collection](https://spatie.be/docs/laravel-medialibrary/working-with-media-collections/defining-media-collections#content-using-a-specific-disk).
52+
By default, files will be uploaded publicly to your storage disk defined in the [Filament configuration file](https://filamentphp.com/docs/forms/installation#publishing-configuration). You can also set the `FILESYSTEM_DISK` environment variable to change this. This is to ensure consistency between all Filament packages. Spatie's disk configuration will not be used, unless you [define a disk for a registered collection](https://spatie.be/docs/laravel-medialibrary/working-with-media-collections/defining-media-collections#content-using-a-specific-disk).
5553

5654
Alternatively, you can manually set the disk with the `disk()` method:
5755

@@ -159,8 +157,8 @@ It's possible to target a file upload component to only handle a certain subset
159157
For example, you could scope the field to only handle media that has certain custom properties:
160158

161159
```php
160+
use Filament\Schemas\Components\Utilities\Get;
162161
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
163-
use Filament\Forms\Get;
164162
use Illuminate\Support\Collection;
165163

166164
SpatieMediaLibraryFileUpload::make('images')

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"source": "https://github.com/filamentphp/filament"
99
},
1010
"require": {
11-
"php": "^8.1",
12-
"illuminate/support": "^10.45|^11.0|^12.0",
13-
"spatie/laravel-medialibrary": "^10.0|^11.0"
11+
"php": "^8.2",
12+
"filament/support": "self.version",
13+
"spatie/laravel-medialibrary": "^11.0"
1414
},
1515
"autoload": {
1616
"psr-4": {

src/Forms/Components/SpatieMediaLibraryFileUpload.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ protected function setUp(): void
7373
$component->state($media);
7474
});
7575

76-
$this->afterStateHydrated(static function (BaseFileUpload $component, string | array | null $state): void {
77-
if (is_array($state)) {
78-
return;
79-
}
80-
81-
$component->state([]);
82-
});
76+
$this->afterStateHydrated(null);
8377

8478
$this->beforeStateDehydrated(null);
8579

@@ -122,7 +116,7 @@ protected function setUp(): void
122116
];
123117
});
124118

125-
$this->saveRelationshipsUsing(static function (SpatieMediaLibraryFileUpload $component) {
119+
$this->saveRelationshipsUsing(static function (SpatieMediaLibraryFileUpload $component): void {
126120
$component->deleteAbandonedFiles();
127121
$component->saveUploadedFiles();
128122
});
@@ -251,7 +245,7 @@ public function deleteAbandonedFiles(): void
251245

252246
$record
253247
->getMedia($this->getCollection() ?? 'default')
254-
->whereNotIn('uuid', array_keys($this->getState() ?? []))
248+
->whereNotIn('uuid', array_keys($this->getRawState() ?? []))
255249
->when($this->hasMediaFilter(), fn (Collection $media): Collection => $this->filterMedia($media))
256250
->each(fn (Media $media) => $media->delete());
257251
}

src/Infolists/Components/SpatieMediaLibraryImageEntry.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ protected function setUp(): void
2525
parent::setUp();
2626

2727
$this->defaultImageUrl(function (SpatieMediaLibraryImageEntry $component, Model $record): ?string {
28-
if ($component->hasRelationship($record)) {
29-
$record = $component->getRelationshipResults($record);
28+
if ($component->hasStateRelationship($record)) {
29+
$record = $component->getStateRelationshipResults($record);
3030
}
3131

3232
$records = Arr::wrap($record);
@@ -90,8 +90,8 @@ public function getImageUrl(?string $state = null): ?string
9090
return null;
9191
}
9292

93-
if ($this->hasRelationship($record)) {
94-
$record = $this->getRelationshipResults($record);
93+
if ($this->hasStateRelationship($record)) {
94+
$record = $this->getStateRelationshipResults($record);
9595
}
9696

9797
$records = Arr::wrap($record);
@@ -132,8 +132,8 @@ public function getState(): array
132132
{
133133
$record = $this->getRecord();
134134

135-
if ($this->hasRelationship($record)) {
136-
$record = $this->getRelationshipResults($record);
135+
if ($this->hasStateRelationship($record)) {
136+
$record = $this->getStateRelationshipResults($record);
137137
}
138138

139139
$records = Arr::wrap($record);

src/Tables/Columns/SpatieMediaLibraryImageColumn.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function applyEagerLoading(Builder | Relation $query): Builder | Relation
175175

176176
if ($this->hasRelationship($query->getModel())) {
177177
return $query->with([
178-
"{$this->getRelationshipName()}.media" => $modifyMediaQuery,
178+
"{$this->getRelationshipName($query->getModel())}.media" => $modifyMediaQuery,
179179
]);
180180
}
181181

0 commit comments

Comments
 (0)