preview file after upload
Hello all,
I have a wizard with 3 steps, in first one, the user can upload a csv file and after uploading it I want to show the data in table in the same step, how to do that?
3 Replies
To create a wizard in Laravel where the user uploads a CSV file in the first step and views the data in a table on the same step, you can handle it using a combination of a file upload form, validation, and a session to temporarily store the file's contents. In the form for Step 1, use a file input to allow the user to upload the CSV file. On submission, validate and process the file in the controller by using fgetcsv() or a library like Maatwebsite Laravel Excel to read the CSV data into an array. Store the processed data in a session or pass it back to the view directly. Then, render the table dynamically in the same view by iterating over the array containing the CSV data. For example, in your controller, after processing the file, return the same view with the CSV data (e.g., return view('wizard.step1', compact('csvData'))), and in your Blade template, check if csvData exists to display the table dynamically. This approach keeps the user on the same step and shows the uploaded file's data immediately.
Can you show the error you are facing first?
In general the uploaded file should be processed manually as the filament deals with them only in the Import/Export classes not in Fileupload input (Just like you are doing now)
the file upload should be
->live()
In Wizards you can use the ->afterValidation()
method of each step tooThank you guys, I did it.