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

Double Validation: in controller and repository. #31

Open
akozyr opened this issue May 15, 2018 · 2 comments
Open

Double Validation: in controller and repository. #31

akozyr opened this issue May 15, 2018 · 2 comments

Comments

@akozyr
Copy link

akozyr commented May 15, 2018

We have possibility to run a validation in two different way: run a validator directly in the controller and validate request data in the repository during create/update. I have found that when we use the validator in controller we will have double validation on the whole. The discribed situation:

class PostsController
{
    ...

    public function store(...)
    {
        try {
            // the first validation executing
            $this->validator->with($request->all())->passesOrFail();

            $someService->update($request->all(), $id);
        } catch (ValidatorException $e) {
            
        }
    }
}
class SomeService
{
    public function update(...)
    {
        // the second validation executing in the parent method of BaseRepository
        $this->repository->update($data, $id);
    }
}

Question: what is the best way to avoid double validation leaving it only in the controller?

@akozyr
Copy link
Author

akozyr commented May 15, 2018

Will it be correct if we just don't specify validator method in the repository?

@celorodovalho
Copy link

Indeed, it's sucks!
Actually I replace the validator on Controller and just keep it on Repository

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

No branches or pull requests

2 participants