strtolower( trim( $studentData[0] ) ), 'password' => trim( $studentData[1] ), 'email' => trim( $studentData[2] ), 'name' => trim( $studentData[3] ), 'valid_date' => trim( $studentData[4] ), ]; }, $formData ); foreach ( $students as $student ) { // 新增或更新學生資料 User::updateOrCreate( [ 'school_no' => $student['school_no'] ], $student ); // 模擬錯誤(這裡會導致回滾) //throw new Exception("Something went wrong!"); } } }