0

I am using Laravel 6 on a project (included with this chat system / project).
First time so searching for some things.
Using the debugging fucntion of xdebug w/ PHPStorm I can follow it perfectly.
This is what I see:

RegisterController:

    protected function validator(array $data)
{
    $data['name'] = htmlspecialchars($data['name']);

    return Validator::make($data, [
        'name'     => ['required', 'string', 'max:100'],
        'email'    => ['required', 'string', 'email', 'max:255', 'unique:users', 'regex:/^[w-.+][email protected][a-zA-Z0-9.-]+.[a-zA-z0-9]{2,4}$/'],
        'password' => ['required', 'string', 'min:3', 'max:30', 'confirmed', new NoSpaceContaine()],
        'min18years' => ['accepted'],
        'accept_all_agreements' => ['accepted'],
        'medical1' => ['accepted'],
        'medical2' => ['accepted']
    ], [
        'name.required' => 'A name is required',
        'email.required' => 'An email is required',
        'password.required' => 'A password is required',
        'min18years.accepted' => 'An approval for min 18 years is required',
        'accept_all_agreements.accepted' => 'An approval for agreements is required',
        'medical1.accepted' => 'An approval for medical1 is required',
        'medical2.accepted' => 'An approval for medical2 is required'
    ]);
}

$Data (from debugger, On purpose not selected the min18years checkbox):

$data = {array} [9]
 _token = "oEMQFjasGoex4MDiThonh8Vw0e5UbyQ5o7GTRAi8"
 name = "Peter7"
 email = "[email protected]"
 password = "123"
 password_confirmation = "123"
 min18years = "0"
 accept_all_agreements = "yes"
 medical1 = "yes"
 medical2 = "yes"

IlluminateValidationValidator.php:”

    public function validate()
{
    if ($this->fails()) {
        throw new ValidationException($this);
    }

    return $this->validated();
}

Error get’s thrown, the current data when calling “ValidationException”:

$this:

$this = {IlluminateValidationValidator} [27]
 translator = {IlluminateTranslationTranslator} [7]
 container = {IlluminateFoundationApplication} [33]
 presenceVerifier = {IlluminateValidationDatabasePresenceVerifier} [2]
 failedRules = {array} [1]
  min18years = {array} [1]
   Accepted = {array} [0]
 excludeAttributes = {array} [0]
 messages = {IlluminateSupportMessageBag} [2]
  messages = {array} [1]
   min18years = {array} [1]
    0 = "An approval for min 18 years is required"
  format = ":message"
 data = {array} [9]
  _token = "oEMQFjasGoex4MDiThonh8Vw0e5UbyQ5o7GTRAi8"
  name = "Peter7"
  email = "[email protected]"
  password = "123"
  password_confirmation = "123"
  min18years = "0"
  accept_all_agreements = "yes"
  medical1 = "yes"
  medical2 = "yes"
 initialRules = {array} [7]
 rules = {array} [7]
 currentRule = "accepted"
 implicitAttributes = {array} [0]
 implicitAttributesFormatter = null
 distinctValues = {array} [0]
 after = {array} [0]
 customMessages = {array} [7]
  name.required = "A name is required"
  email.required = "An email is required"
  password.required = "A password is required"
  min18years.accepted = "An approval for min 18 years is required"
  accept_all_agreements.accepted = "An approval for agreements is required"
  medical1.accepted = "An approval for medical1 is required"
  medical2.accepted = "An approval for medical2 is required"

But when I follow the call to IlluminateValidationValidationException.php:

public function __construct($validator, $response = null, $errorBag = 'default')
{
    parent::__construct('The given data was invalid.');

    $this->response = $response;
    $this->errorBag = $errorBag;
    $this->validator = $validator;
}

and the $this didn’t receive the messages that was passed along to this function.

$this:

$this = {IlluminateValidationValidationException} [12]
 validator = null
 response = null
 status = {int} 422
 errorBag = null
 redirectTo = null
 message = ""
 *Exception*string = ""
 code = {int} 0
 file = "C:Sourceswachtweken.nlvendorlaravelframeworksrcIlluminateValidationValidator.php"
 line = {int} 386
 *Exception*trace = {array} [44]
 *Exception*previous = null

I hope this is clear when I go throgh te debug steps…

Added validator function as requested (but it’s the default :

   protected function validator(array $data)
    {
        $data['name'] = htmlspecialchars($data['name']);

        return Validator::make($data, [
            'name'     => ['required', 'string', 'max:100'],
            'email'    => ['required', 'string', 'email', 'max:255', 'unique:users', 'regex:/^[w-.+][email protected][a-zA-Z0-9.-]+.[a-zA-z0-9]{2,4}$/'],
            'password' => ['required', 'string', 'min:3', 'max:30', 'confirmed', new NoSpaceContaine()],
            'min18years' => ['accepted'],
            'accept_all_agreements' => ['accepted'],
            'medical1' => ['accepted'],
            'medical2' => ['accepted']
        ], [
            'name.required' => 'A name is required',
            'email.required' => 'An email is required',
            'password.required' => 'A password is required',
            'min18years.accepted' => 'An approval for min 18 years is required',
            'accept_all_agreements.accepted' => 'An approval for agreements is required',
            'medical1.accepted' => 'An approval for medical1 is required',
            'medical2.accepted' => 'An approval for medical2 is required'
        ]);
    }