Components\FileUpload::make('image')->label('Image')->image()->required() ->disk(config('filesystems.default')) ->directory(config('filesystems.disks.'.config('filesystems.default').'.root')) ->afterStateHydrated(static function (\Filament\Forms\Components\BaseFileUpload $component, string | array | null $state): void { if (blank($state)) { $component->state([]); return; } $state = \Arr::last(explode('/', $state)); $files = collect(\Arr::wrap($state)) ->filter(static function (string $file) use ($component): bool { try { return blank($file) || $component->getDisk()->exists($file); } catch (\League\Flysystem\UnableToCheckFileExistence $exception) { return false; } }) ->mapWithKeys(static fn (string $file): array => [((string) \Str::uuid()) => $file]) ->all(); $component->state($files); })
afterStateHydrated()
Components\FileUpload::make('image')->label('Image')->image()->required() ->disk(config('filesystems.default')) ->directory(config('filesystems.'.config('filesystems.default').'.root')) ->afterStateHydrated(function($component, $record) { if ($record) { $filename = \Arr::last(explode('/', $record->image)); $component->state([$filename => $filename]); } })
Components\Select::make('categories')->label('category') ->multiple() ->options(function(callable $get) { return ['0' => 'all']; }),