Form with no model
We have to process uploads on a regular basis. So far we've cheated and put the form upload into one table (model) and the data into another table (model). But we have several cases where we simply don't need to store the file. We want the data inside the file import into a model. For example we have a CSV with serial numbers and want to import them into a model called serial numbers.
I don't think the right thing to do is put a form field on the serial number model. What I've done so far is simply hooked into the saved event for the model and parsed the upload and saved it to the data table for that file model.
I think we could accomplish the same results by creating a custom page with a custom widget that has the file upload form on it. And then simply clean parse the file (either via queue or inline if small). Just want to make sure I'm on the right track here before we get too far into these projects.
Anyone done this and happen to have an example? This need comes up super often.
We are using the entire Filament suite (admin panel, form builder, table builder and notifications, just for reference). Everything is inside the Admin Panel.
4 Replies
I did similar to what you have done, but in the action model, we access the file that was uploaded to temp then parse it, clean it, rendering it in a custom table view showing the dataset to ensure it's correct, and then click process to import. Then the file is only saved into tmp and not stored into the database
Thanks. I had a feeling that was the case. We are testing out a couple different ways to solve this to figure out which one we like best.
in v3 there is a method to prevent it from being saved permanently
because i also needed it in a project
Excellent! It's not hard to clean up the file after but wanted to make sure I wasn't missing something. Very excited about V3 already and this will be very handy. Thanks again for all the hard work you and everyone put into Filament.