schema([ Forms\Components\TextInput::make('name') ->label('File Name'), Forms\Components\FileUpload::make('attachment') ->label('Upload') // ->acceptedFileTypes(['application/pdf']) ->storeFiles(false) ->disk('local') ->directory('uploads/temp') ->preserveFilenames() ->reactive(), Forms\Components\Actions::make([ Action::make('uploadNow') ->label('File Upload') ->action(function ($get) { $uploadedFiles = $get('attachment'); if (is_array($uploadedFiles) && count($uploadedFiles) > 0) { $uploaded = reset($uploadedFiles); if ($uploaded instanceof TemporaryUploadedFile) { $baseName = $get('name'); $extension = $uploaded->getClientOriginalExtension(); $finalFileName = $baseName . '.' . $extension; $uploaded->storeAs( 'uploads', $finalFileName, 'local' ); Notification::make() ->title("File uploaded successfully: {$finalFileName}") ->success() ->send(); } } else { Notification::make() ->title('No file selected to upload') ->warning() ->send(); } }), Action::make('downloadAttachment') ->label('Download File') ->action(function ($get) { $fileName = $get('name'); if (!$fileName) { Notification::make() ->title('Enter file name to download') ->danger() ->send(); return; } $files = Storage::disk('local')->files('uploads'); foreach ($files as $file) { if (pathinfo($file, PATHINFO_FILENAME) === $fileName) { Notification::make() ->title("File downloaded successfully") ->success() ->send(); return response()->download( Storage::disk('local')->path($file) ); } } Notification::make() ->title('File not found') ->danger() ->send(); }), ]), Forms\Components\Hidden::make('created_by') ->label('Created By') ->default(Filament::auth()->user()?->name), Forms\Components\Hidden::make('updated_by') ->label('Updated By') ->default(Filament::auth()->user()?->name), ]); } public static function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('id') ->label('ID') ->numeric() ->sortable(), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('deleted_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ->filters([ Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListTestingTemps::route('/'), 'create' => Pages\CreateTestingTemp::route('/create'), 'view' => Pages\ViewTestingTemp::route('/{record}'), 'edit' => Pages\EditTestingTemp::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); } }