Skip to content

[8.x] Rule::exists does not cast true or false correctly since last patch #36459

@RikSomers

Description

@RikSomers
  • Laravel Version: 8.30.1
  • PHP Version: 7.4.15
  • Database Driver & Version: SQL Server 2017

Description:

When passing true or false to a where clause in the Exists rule, it will transform the value in the database to the literal true and false. Previously, if you used for example tinyint for your boolean column it would cast it correctly.

Steps To Reproduce:

Given that you have a database with a column that is a tinyint (e.g. BlockedIndicator).

And given that you have a validation rule:

public function rules()
{
        return [
                'code' => ['required', Rule::exists('Location', 'LocationCode')->where('BlockedIndicator', false)]
        ]
}

Previously it would correctly pass or fail the validation based on whether there was a location that had it's BlockedIndicator as false.

Now however, the validation errors out with the following query exception:

[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value 'false' to data type tinyint

This has been broken since #36441 , which was reverted here #36452 and reverted back to the new code here #36453

Our Case

We use a database(not in our control how the database is structured) that has multiple "boolean" columns as tinyints. We can normally query these columns using php booleans like the following:

Location::where('BlockedIndicator', false)->get()

So throughout the codebase we have also adopted this pattern for our rules, as explained above. This has worked for quite some time now, and since the last Laravel patch release (8.30.1) this has been breaking all of our feature tests throughout the whole code base.

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