meness's avatar

Fatal error: Maximum function nesting level of '512' reached, aborting in Arr.php on line 20

Hi,

$validator::passes() method throws the exception noted in the title, but using empty($validator->failed()) statement is okay. I think this is a high priority bug with Lumen/Laravel.

trait ValidateTrait
{
    public static function validate(Collection $data, array $rules, \Closure $closure = null): MessageBag
    {
        $validator = FacadeValidator::make($data->toArray(), $rules);
        if ($closure != null) {
            $validator->after($closure);
        }
        return $validator->errors();
    }
}
final class ProjectReport extends ReportBaseModel implements IProjectReport
{
    public static $rules = [
        'project_id' => 'bail|numeric|required',
        'report_id' => 'bail|numeric',
    ];

    // some relationships

    public static function validate(Collection $data): MessageBag
    {
        $reportValidator = ValidateTrait::validate($data, Report::$rules, null);
        $validator = ValidateTrait::validate($data, ProjectReport::$rules, function (Validator $validator) use ($reportValidator, $data) {
            if ($validator->passes()) { // the line throws the exception
                if (!Project::id($data->get('project_id'))->exists()) {
                    $validator->add('project_id', 'the project doesn\'t exist');
                }
            }
        });

        return $validator->merge($reportValidator);
    }
}
0 likes
0 replies

Please or to participate in this conversation.