Skip to content

WhereIn with integer returns partial match on string. (int) 1 returns (string) '1ab1fdeb-7e83-4be9-a1b4-52da267d2733' #31441

@booni3

Description

@booni3
  • Laravel Version: 6.12.0
  • PHP Version: 7.4.0
  • Database Driver & Version: MySQL 8.0

Description:

Passing an integer 1 into a whereIn against a string column (i.e. UUID), returns a match against 1ab1fdeb-7e83-4be9-a1b4-52da267d2733

Model::whereIn('uuid', [1])
    ->each(function(Model $model) {
        dd($model->uuid); // '1ab1fdeb-7e83-4be9-a1b4-52da267d2733'
    });

To prevent this from happening you have to force the whereIn array to a string, which is not very intuitive, even if technically correct.

Model::whereIn('uuid', array_map('strval', $this->ids)); // returns no results as expected

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