schema([ Forms\Components\TextInput::make('name') ->label('File Name'), Forms\Components\Select::make('selected_file') ->label('Select Uploaded File') ->options(function () { return collect(Storage::disk('local')->files('uploads')) ->mapWithKeys(function ($file) { return [ $file => basename($file), // value => label ]; }) ->toArray(); }) ->searchable() ->reactive(), Forms\Components\FileUpload::make('attachment') ->label('Upload') // ->acceptedFileTypes(['application/pdf']) ->storeFiles(false) ->disk('local') ->directory('uploads/temp') ->preserveFilenames() ->maxSize(20480) ->reactive(), Forms\Components\Actions::make([ Action::make('uploadNow') ->label('File Upload') ->color('success') ->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 = basename($get('selected_file')); // //dd($fileName); // // 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) { // dd($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(); // }), Action::make('downloadAttachment') ->label('Download File') ->action(function ($get) { $filePath = $get('selected_file'); // uploads/filename.pdf if (!$filePath || !Storage::disk('local')->exists($filePath)) { Notification::make() ->title('File not found') ->danger() ->send(); return; } Notification::make() ->title('File downloaded successfully') ->success() ->send(); return response()->download( Storage::disk('local')->path($filePath) ); }), Action::make('deleteAttachment') ->label('Delete File') ->color('danger') ->requiresConfirmation() ->action(function ($get) { $filePath = $get('selected_file'); // uploads/filename.pdf if (!$filePath || !Storage::disk('local')->exists($filePath)) { Notification::make() ->title('File not found') ->danger() ->send(); return; } Storage::disk('local')->delete($filePath); Notification::make() ->title('File deleted successfully') ->success() ->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, ]); } }