O
O
onlinejunior2020-07-11 12:21:49
Laravel
onlinejunior, 2020-07-11 12:21:49

How to check data by condition in validate in laravel?

Let's say I have a database with fields that contain data.

id, cat, name, value

I'm entering data and want to check if an ID belongs to NAME.

This is how it all works:

$this->validate($request, [
            'nd' => 'required|regex:/^[0-9]{1,3}$/|exists:meta,id',
        ], $message);


How can I check the entered ID against the name field?

It's something like:

SELECT id FROM meta WHERE id = 1 AND name = 'name'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-07-11
@Yadalay

If I understood correctly, then here is the link , namely the subsection "Forcing A Unique Rule To Ignore A Given ID".
If you didn't guess, then it's probably a link , namely the withValidator() method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question