Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoload validation classes from Validator #767

Merged

Conversation

eaguad1337
Copy link
Member

In docs, you could see something like this:

from masonite.validation import Validator
from masonite.validation import required, accepted
from masonite.request import Request
from masonite.response import Response

def show(self, request: Request, response: Response, validate: Validator):
    """
    Incoming Input: {
        'user': 'username123',
        'email': '[email protected]',
        'terms': 'on'
    }
    """
    errors = request.validate(
        validate.required(['user', 'email']),
        validate.accepted('terms')
    )

    if errors:
        return response.back().with_errors(errors)

Specifically, this two lines will raise an error, because required and accepted are not attributes of Validator class. Instead, you should import the class from masonite.validation, but, in order to make it work more naturally, I propose this fix to make it work.

validate.required(['user', 'email']),
validate.accepted('terms')

@josephmancuso josephmancuso merged commit 0c473ba into MasoniteFramework:4.0 Dec 6, 2023
@eaguad1337 eaguad1337 deleted the fix/autoload-validations branch December 6, 2023 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants