src/classes/Utilities/Validator.php
public static function validate($request, $rules, $messages=[])
    {
        $errors = [];
        $files = $request->getUploadedFiles();

        foreach ($rules as $field => $rule)
        {
            try
            {
                if ($rule instanceof v)
                {
                    // check if the field is for file
                    if (isset($files[$field]))
                    {
                        if (is_array($files[$field])) // multiple file
                        {
                            $files = $files[$field];
                            foreach ($files as $file_row)
                            {
                                if ($file_row instanceof UploadedFile)
                                {
                                    $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($file_row->file));
                                }
                            }
                        }
                        else // single file
                        {
                            if ($files[$field] instanceof UploadedFile)
                            {
                                $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($files[$field]->file));
                            }
                        }
                    }
                    else
                    {
                        $rule->setName(str_title(ucfirst($field)))->assert($request->getParam($field));
                    }
                }
                else
                {
                    \Log::error("Error: Rule must be Respect\Validation\Validator object");
                }
            } catch (NestedValidationException $e) {
                $translator = config('validation.translator');
                $e->setParam('translator', function($message) use($translator) {
                    $language = $translator['lang'];
                    $messages = $translator['messages'];

                    return isset($messages[$message]) ? $messages[$message][$language] : $message;
                });

                $e->findMessages($messages);
                $errors[$field] = $e->getMessages();
            }
        }
        Session::set('errors', $errors);
        return __CLASS__;
    }
public static function validate($request, $rules, $messages=[])
    {
        $errors = [];
        $files = $request->getUploadedFiles();

        foreach ($rules as $field => $rule)
        {
            try
            {
                if ($rule instanceof v)
                {
                    // check if the field is for file
                    if (isset($files[$field]))
                    {
                        if (is_array($files[$field])) // multiple file
                        {
                            $files = $files[$field];
                            foreach ($files as $file_row)
                            {
                                if ($file_row instanceof UploadedFile)
                                {
                                    $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($file_row->file));
                                }
                            }
                        }
                        else // single file
                        {
                            if ($files[$field] instanceof UploadedFile)
                            {
                                $rule->setName(str_title(ucfirst($field)))->assert(new \SplFileInfo($files[$field]->file));
                            }
                        }
                    }
                    else
                    {
                        $rule->setName(str_title(ucfirst($field)))->assert($request->getParam($field));
                    }
                }
                else
                {
                    \Log::error("Error: Rule must be Respect\Validation\Validator object");
                }
            } catch (NestedValidationException $e) {
                $translator = config('validation.translator');
                $e->setParam('translator', function($message) use($translator) {
                    $language = $translator['lang'];
                    $messages = $translator['messages'];

                    return isset($messages[$message]) ? $messages[$message][$language] : $message;
                });

                $e->findMessages($messages);
                $errors[$field] = $e->getMessages();
            }
        }
        Session::set('errors', $errors);
        return __CLASS__;
    }
public static function validate ( $ request , $ rules , $ messages = [ ] ) { $ errors = [ ] ; $ files = $ request -> getUploadedFiles ( ) ; foreach ( $ rules as $ field => $ rule ) { try { if ( $ rule instanceof v ) { // check if the field is for file if ( isset ( $ files [ $ field ] ) ) { if ( is_array ( $ files [ $ field ] ) ) // multiple file { $ files = $ files [ $ field ] ; foreach ( $ files as $ file_row ) { if ( $ file_row instanceof UploadedFile ) { $ rule -> setName ( str_title ( ucfirst ( $ field ) ) ) -> assert ( new \ SplFileInfo ( $ file_row -> file ) ) ; } } } else // single file { if ( $ files [ $ field ] instanceof UploadedFile ) { $ rule -> setName ( str_title ( ucfirst ( $ field ) ) ) -> assert ( new \ SplFileInfo ( $ files [ $ field ] -> file ) ) ; } } } else { $ rule -> setName ( str_title ( ucfirst ( $ field ) ) ) -> assert ( $ request -> getParam ( $ field ) ) ; } } else { \ Log :: error ( "Error: Rule must be Respect\Validation\Validator object" ) ; } } catch ( NestedValidationException $ e ) { $ translator = config ( 'validation.translator' ) ; $ e -> setParam ( 'translator' , function ( $ message ) use ( $ translator ) { $ language = $ translator [ 'lang' ] ; $ messages = $ translator [ 'messages' ] ; return isset ( $ messages [ $ message ] ) ? $ messages [ $ message ] [ $ language ] : $ message ; } ) ; $ e -> findMessages ( $ messages ) ; $ errors [ $ field ] = $ e -> getMessages ( ) ; } } Session :: set ( 'errors' , $ errors ) ; return __CLASS__ ; }
Put all fails in session
@param  Psr\Http\Message\RequestInterface $request
@param  array $rules
@return SkeletonCore\Utilities\Validator
Put all fails in session