get()->toArray(); // dd($data); return view('Admin.Pages.direct_users.direct_user')->with(['user_data'=> $data]); } public function import(Request $request) { try { $validation = $request->validate([ 'csv_file' => 'required|mimes:csv,txt,xlsx', ]); // dd($request->all()); // Use try-catch to handle exceptions thrown by Excel::import // try { Excel::import(new UserImport, $request->file('csv_file')); return response()->json(['success' => true, 'status' => 200]); // } catch (ValidationException $e) { // // Catch the validation exception and extract errors // $errors = $e->validator->errors()->toArray(); // return response()->json(['errors' => $errors], 422); // 422 Unprocessable Entity // } } catch (\Exception $e) { return response()->json(['error' => 'Error importing data: ' . $e->getMessage()], 500); } } }