Skip to content

Model validation with all the fields together #1199

Closed Answered by Mte90
Mte90 asked this question in Q&A (Help)
Discussion options

You must be logged in to vote

I was able to find the solution with chatgpt because on google I wasn't very lucky.

So in your StoreRequest a code like this is executed on saving of the CRUD so it is possible to access all the data and do what you need:

    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            $data = $this->all();
            dd($data);
            if ($data['campo1'] === $data['campo2']) {
                $validator->errors()->add('campo2', 'an error.');
            }
        });
    }

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@Mte90
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Mte90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants