1

I have a dialog for checking in a visitor. On submit I would like to check the database if values exists. I'm having some trouble building up the validator.

There are two tables.

table: visitor
- id
- name
- signed_agreement
- ...

table: visit_type
- id
- name
- require_agreement

While submitting the form I send two values; the visitor id and visit_type id. If the visit_type require_agreement column is equal to 1, the signed_agreement of the visitor should also be 1. If not, the validation should fail.

Any suggestions?

1 Answer 1

1

You can use exists:table,column to check if the value exists on db or not. You must add different validations for each table & field pair.

Sign up to request clarification or add additional context in comments.

5 Comments

That part I understand, but I want to check 2 fields that are not part of the form. How can I check for visit_type.require_agreement == 1 and visitor.signed_agreement == 1
It looks like not related to validation. You should add where filters to your Eloquent or Database queries. Are you newbie on Laravel? If I know that I can guide you more detailed.
So I should let the form validation for what it is and do some custom validation in the store controller? Create a visit_type / visitor relation and maybe its own method like; visitor->hasSignedAgreement() ?
Do you get visitor id and visit_type id via form input? What are your request inputs exactly? Do you mean that you get only visitor id but want to check same data against to either visitor id and visit_type id?
When I submit the form I send the visitor.id and the visit_type.id. What I want to do is look up the visit_type.id and get the visit_type.require_agreement. If the visit_type.require_agreement column is equal to 1 it means the visitor needs a signed agreement. Then it should find the visitor and check of the visitor.signed_agreement column is set to 1. If is does, the form is valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.