StoreUsernameRequest.php 806 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Http\Requests;
  3. use App\Rules\NotBlacklisted;
  4. use App\Rules\NotDeletedUsername;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. class StoreUsernameRequest extends FormRequest
  7. {
  8. /**
  9. * Determine if the user is authorized to make this request.
  10. *
  11. * @return bool
  12. */
  13. public function authorize()
  14. {
  15. return true;
  16. }
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array
  21. */
  22. public function rules()
  23. {
  24. return [
  25. 'username' => [
  26. 'required',
  27. 'regex:/^[a-zA-Z0-9]*$/',
  28. 'max:20',
  29. 'unique:usernames,username',
  30. new NotBlacklisted(),
  31. new NotDeletedUsername(),
  32. ],
  33. ];
  34. }
  35. }