Compare commits
2 Commits
f6f6f0924e
...
99f7450e5e
| Author | SHA1 | Date | |
|---|---|---|---|
| 99f7450e5e | |||
|
|
84748c5e3d |
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user