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

This commit is contained in:
dhanabalan
2026-01-06 19:18:22 +05:30
parent 4ec781b942
commit 84748c5e3d

View File

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