$user = new User(); $user->email = $request->email; $user->password = Hash::make($request->password); $user->level = 0; $user->status = 1; if ($user->save()) {//save là reg nếu thành công $credentials = [ 'email' => $request->email, 'password' => $request->password, 'status' => 1 //có thể bỏ qua dòng này ]; if (Auth::attempt($credentials)) {//lệnh trong if là login nếu thành công Auth::user()->sendEmailVerificationNotification(); //gửi mail xác nhận, ko cần thì bỏ qua dòng này $notification = ['flag' => 'success', 'message' => 'Thank you to us!
Please check your email for a verification.
Wish you a good day!']; //thông báo kiểu json gửi qua js return redirect('/')->with($notification); } } } else { $notification = ['flag' => 'error', 'message' => 'Could not verify you. Please try again!']; return redirect()->back()->with($notification)->withInput(); }