Amir Sasani
Amir Sasani

Reputation: 327

laravel validation check field equal something

how to check a field is exactly equal to a string or number
I want to check a field named course_id is equal a field of database id in course database. now I want to check if course_id is equal to id.

Upvotes: 0

Views: 2019

Answers (2)

Osama Sayed
Osama Sayed

Reputation: 2023

You can validate it by using the exists validation rule:

$validationRules = ['course_id' => 'exists:course,id'];

Upvotes: 1

Laravel User
Laravel User

Reputation: 1129

create rule as below and use validator on input

$rules = array(
        'id'    => 'exists:your_table_name'
    );

for more help https://laravel.com/docs/5.2/validation#rule-exists

Upvotes: 0

Related Questions