2 Commits

Author SHA1 Message Date
99f7450e5e Merge pull request 'changed logic in testing temp resource page' (#174) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Reviewed-on: #174
2026-01-06 13:48:37 +00:00
dhanabalan
84748c5e3d changed logic in testing temp resource page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / review (pull_request) Failing after 23s
Laravel Pint / pint (pull_request) Successful in 3m49s
Laravel Larastan / larastan (pull_request) Failing after 4m51s
2026-01-06 19:18:22 +05:30

View File

@@ -30,6 +30,19 @@ class TestingTempResource extends Resource
->schema([ ->schema([
Forms\Components\TextInput::make('name') Forms\Components\TextInput::make('name')
->label('File 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') Forms\Components\FileUpload::make('attachment')
->label('Upload') ->label('Upload')
// ->acceptedFileTypes(['application/pdf']) // ->acceptedFileTypes(['application/pdf'])
@@ -41,6 +54,7 @@ class TestingTempResource extends Resource
Forms\Components\Actions::make([ Forms\Components\Actions::make([
Action::make('uploadNow') Action::make('uploadNow')
->label('File Upload') ->label('File Upload')
->color('success')
->action(function ($get) { ->action(function ($get) {
$uploadedFiles = $get('attachment'); $uploadedFiles = $get('attachment');
@@ -76,41 +90,94 @@ class TestingTempResource extends Resource
} }
}), }),
// 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') Action::make('downloadAttachment')
->label('Download File') ->label('Download File')
->action(function ($get) { ->action(function ($get) {
$fileName = $get('name'); $filePath = $get('selected_file'); // uploads/filename.pdf
if (!$fileName) { if (!$filePath || !Storage::disk('local')->exists($filePath)) {
Notification::make() Notification::make()
->title('Enter file name to download') ->title('File not found')
->danger() ->danger()
->send(); ->send();
return; return;
} }
$files = Storage::disk('local')->files('uploads'); Notification::make()
->title('File downloaded successfully')
->success()
->send();
foreach ($files as $file) { return response()->download(
if (pathinfo($file, PATHINFO_FILENAME) === $fileName) { 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() Notification::make()
->title("File downloaded successfully") ->title('File not found')
->success() ->danger()
->send(); ->send();
return response()->download( return;
Storage::disk('local')->path($file)
);
} }
}
Notification::make() Storage::disk('local')->delete($filePath);
->title('File not found')
->danger() Notification::make()
->send(); ->title('File deleted successfully')
}), ->success()
->send();
}),
]), ]),
Forms\Components\Hidden::make('created_by') Forms\Components\Hidden::make('created_by')
->label('Created By') ->label('Created By')