validate([ 'email' => ['required', 'email:rfc,dns'], 'password' => ['required'], 'password2' => ['required', 'same:password'] ]); //How Many user already exists, check to make the first user admin $userCount = User::query()->count('id'); $user = new User(); $user->email = $validatedData["email"]; $user->password = Hash::make($validatedData["password"]); $user->saveOrFail(); $privilege = new Privilege(); $privilege->user_id = $user->id; if($userCount == 0) { $privilege->admin = true; $privilege->createVPN = true; } $privilege->saveOrFail(); return redirect("/login"); } public function login(Request $request) { $validatedData = $request->validate([ 'email' => ['required', 'email:rfc'], 'password' => ['required'] ]); if(Auth::attempt($validatedData)) { return redirect("/dashboard"); } return view("public.login", ["msg"=> "Login failed"]); } }