Skip to content

Commit cd53927

Browse files
committed
change collection functionality
1 parent 5eff9e0 commit cd53927

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

packages/media/src/Resources/MediaResource.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Filament\Resources\Resource;
99
use Filament\Forms\Components\View;
1010
use Illuminate\Support\Facades\Log;
11+
use Filament\Forms\Components\Select;
1112
use Filament\Forms\Components\Section;
1213
use Filament\Forms\Components\Textarea;
1314
use Filament\Tables\Actions\EditAction;
@@ -327,6 +328,22 @@ class=\"filament-button filament-button-size-sm inline-flex items-center justify
327328
');
328329
}),
329330

331+
Select::make('collection_name')
332+
->label(__('media::fields.collection'))
333+
->disabled(fn($record) => $record?->getOriginal('write_protected'))
334+
->options(function () {
335+
return Media::query()
336+
->distinct()
337+
->pluck('collection_name', 'collection_name')
338+
->toArray();
339+
})
340+
->default(fn($record) => $record->collection_name)
341+
->afterStateUpdated(function ($state, $record) {
342+
if ($state !== $record->collection_name) {
343+
$record->collection_name = $state;
344+
$record->save();
345+
}
346+
}),
330347
])
331348
->columns(4),
332349

@@ -796,7 +813,7 @@ public static function table(Table $table): Table
796813

797814
return $query;
798815
}),
799-
SelectFilter::make('collection')
816+
SelectFilter::make('collection_name')
800817
->label(__('media::fields.collection'))
801818
->options(function () {
802819
return Media::query()

0 commit comments

Comments
 (0)