Skip to content

Request validation with an ::exists() rule passes validation with wrong value #54183

@liviublidar

Description

@liviublidar

Laravel Version

11.23

PHP Version

8.2.26

Database Driver & Version

MySQL 8.0.31 on MacOS arm

Description

Request validation with an ::exists() rule passes validation with a value that does not exist in the table.
Let's assume the table users has a foreign_id field it is possible to have the below validation rules and send a request containing '123aabbcc' in the foreign_id value and the validation will pass as long as foreign_table has a row with an id of 123.


 class UpdateUserRequest extends FormRequest
 {
     public function rules(): array
     {
       return [
           'foreign_id' => [
               'required',
                Rule::exists(ForeignTable::class, 'id'),
            ],
        ];
    }
}

Steps To Reproduce

  1. create a validaiton rule containging ::exists()
  2. insert just one row in the table that gets checked in the ::exists(), with an id of 1
  3. make a postman request where the ::exists checks for a value of '1aabbcc'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions