all(); if (get_frontend_settings('recaptcha_status') == true && check_recaptcha($input['g-recaptcha-response']) == false) { Session::flash('error', get_phrase('Recaptcha verification failed')); return redirect(route('register.form')); } $validator = Validator::make($request->all(), [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'email', 'unique:users,email'], 'password' => ['required', Rules\Password::defaults()], ], [ 'name.required' => get_phrase('Name is required'), 'name.string' => get_phrase('Name must be a valid text'), 'name.max' => get_phrase('Name may not be greater than 255 characters'), 'email.required' => get_phrase('Email is required'), 'email.string' => get_phrase('Email must be a valid text'), 'email.email' => get_phrase('Please enter a valid email address'), 'email.unique' => get_phrase('This email is already registered. Please use a different email.'), 'password.required' => get_phrase('Password is required'), 'password.min' => get_phrase('Password must be at least 8 characters'), ]); if ($validator->fails()) { // Get the first error message to show as flash message $firstError = $validator->errors()->first(); Session::flash('error', $firstError); return redirect()->back()->withErrors($validator)->withInput(); } $user_data = [ 'name' => $request->name, 'email' => $request->email, 'role' => 'student', 'status' => 1, 'password' => Hash::make($request->password), ]; if (get_settings('student_email_verification') != 1) { $user_data['email_verified_at'] = Carbon::now(); } $user = User::create($user_data); event(new Registered($user)); Auth::login($user); // If applying as an instructor, process the application if ($request->has('instructor')) { // Check if application already exists if (Application::where('user_id', $user->id)->exists()) { Session::flash('error', get_phrase('Your request is in process. Please wait for admin to respond.')); return redirect()->route('become.instructor'); } // Process instructor application $application['user_id'] = $user->id; $application['phone'] = $request->phone; $application['description'] = $request->description; // Upload document $doc = $request->file('document'); $application['document'] = 'uploads/applications/' . $user->id . Str::random(20) . '.' . $doc->extension(); FileUploader::upload($doc, $application['document'], null, null, 300); // Store application Application::insert($application); Session::flash('success', get_phrase('Your application has been submitted.')); } return redirect(RouteServiceProvider::HOME); } }