You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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:
Question: what is the best way to avoid double validation leaving it only in the controller?
The text was updated successfully, but these errors were encountered: