CreateNewUser.php 901 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Actions\Fortify;
  3. use App\Models\User;
  4. use Illuminate\Support\Facades\Hash;
  5. use Illuminate\Support\Facades\Validator;
  6. use Laravel\Fortify\Contracts\CreatesNewUsers;
  7. class CreateNewUser implements CreatesNewUsers
  8. {
  9. use PasswordValidationRules;
  10. /**
  11. * Validate and create a newly registered user.
  12. *
  13. * @param array $input
  14. * @return \App\Models\User
  15. */
  16. public function create(array $input)
  17. {
  18. Validator::make($input, [
  19. 'name' => ['required', 'string', 'max:255'],
  20. 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
  21. 'password' => $this->passwordRules(),
  22. ])->validate();
  23. return User::create([
  24. 'name' => $input['name'],
  25. 'email' => $input['email'],
  26. 'password' => Hash::make($input['password']),
  27. ]);
  28. }
  29. }