To upload files without saving file information to the database using Filament 3.x, you can follow these steps:
- Create a new Filament resource for handling the file upload. Let's assume the resource is named "FileUploadResource". Run the following command to generate the resource:
php artisan filament:resource FileUploadResource
- In the generated "FileUploadResource" class, modify the
fieldsmethod to include the file upload field:
use Filament\Resources\Forms\Components\FileUpload;
public function fields()
{
return [
FileUpload::make('Prospect Upload')
->disk('upload')
->directory('prospects/json')
->visibility('private')
->maxSize(512)
->preserveFilenames()
->multiple()
->storeFileNamesIn('attachment_file_names')
->uploadButtonPosition('left')
->uploadProgressIndicatorPosition('left'),
];
}
- In your controller or wherever you handle the form submission, you can access the uploaded files using the
attachment_file_namesfield:
use App\Filament\Resources\FileUploadResource;
public function store(Request $request)
{
$validatedData = $request->validate([
'attachment_file_names' => 'required|array',
'attachment_file_names.*' => 'file|max:512',
]);
// Handle the uploaded files here
return redirect()->back()->withSuccess('Files uploaded successfully.');
}
Note that you don't need to save the file information to the database since you mentioned that you don't want to save it. You can handle the uploaded files in the controller or wherever you need to process them.
Remember to update the namespace and use statements according to your application's structure.
I hope this helps! Let me know if you have any further questions.