Hello I am using the Bulk upload of the data in my laravel
public function store(Request $request)
{
$request->validate([
'document' => 'required',
'cat_id' => 'required|numeric',
'status' => 'required|in:active,inactive',
]);
// Get the uploaded file
$file = $request->file('document');
if ($request->cat_id == 1) {
// Import data using FastExcel
$data = (new FastExcel)->import($file);
// Additional processing, if needed
// For example, you can loop through the imported data and store it in the database
foreach ($data as $row) {
$report = SbiMainUpsReport::create($row);
// Attach selected user IDs to the report
// $report->selectedUserIds = $request->user_id;
$report->save();
}
}
if($request->cat_id == 2) {
$data = (new FastExcel)->import($file);
foreach($data as $row) {
$report = StatusReport::create($row);
$report->save();
}
}
if($request->cat_id == 3) {
$data = (new FastExcel)->import($file);
foreach($data as $row) {
$report = PspbEventReport::create($row);
$report->save();
}
}
if($request->cat_id == 4) {
$data = (new FastExcel)->import($file);
foreach($data as $row) {
$report = PspbircEventReport::create($row);
$report->save();
}
}
// Store other form data (category, status, user_id) in your database tables as needed
return back()->with('success','Data inserted successfully');
}
this is my controller loogic to upload the bulk data through .xlsx file
use Rap2hpoutre\FastExcel\FastExcel;
this is the package i am using to upload the data in bulk through excel
but i am not getting that what is the issue when i am uplaoding the 80,000 data it taking 2 min how can i optimize the code so that it get uploaded within 10 sec and my server is also very fast so there is no issue of the serve.
please help and Thank you in advance for helping