Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RegisteredUserController.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\User;
  5. use App\Providers\RouteServiceProvider;
  6. use Illuminate\Auth\Events\Registered;
  7. use Illuminate\Http\RedirectResponse;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. use Illuminate\Support\Facades\Hash;
  11. use Illuminate\Validation\Rules;
  12. use Illuminate\View\View;
  13. class RegisteredUserController extends Controller
  14. {
  15. /**
  16. * Display the registration view.
  17. */
  18. public function create(): View
  19. {
  20. return view('auth.register');
  21. }
  22. /**
  23. * Handle an incoming registration request.
  24. *
  25. * @throws \Illuminate\Validation\ValidationException
  26. */
  27. public function store(Request $request): RedirectResponse
  28. {
  29. $request->validate([
  30. 'name' => ['required', 'string', 'max:255'],
  31. 'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
  32. 'password' => ['required', 'confirmed', Rules\Password::defaults()],
  33. ]);
  34. $user = User::create([
  35. 'name' => $request->name,
  36. 'email' => $request->email,
  37. 'password' => Hash::make($request->password),
  38. ]);
  39. event(new Registered($user));
  40. Auth::login($user);
  41. return redirect(RouteServiceProvider::HOME);
  42. }
  43. }