validate([ 'file' => 'required|file|mimes:xlsx,csv,xls|max:10240', ]); $import = new TaskImport($project); try { Excel::import($import, $request->file('file')); } catch (\Exception $e) { return back()->with('error', 'Import failed: ' . $e->getMessage()); } $count = $import->getImportedCount(); $message = "{$count} task(s) imported successfully."; if ($import->getSkippedCount() > 0) { $message .= " {$import->getSkippedCount()} row(s) skipped."; } return back()->with('success', $message); } }