1
votes

I'm using Laravel Framework (8.26) and PHP 8.0.5

My database is Postgresql (12.3)

This is my schema (cities table):

Column Type Collation Nullable Default
id bigint not null
is_active boolean not null true

It also has lots of other fields which are not relevant to my question.

I've created a model for this table:

class City extends Model
{
    public $timestamps = false;
    protected $table = 'cities';
}

Then when I use the query builder:

City::where('is_active', true)->get();

It raises an error:

Illuminate\Database\QueryException
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: boolean = integer LINE 1: select * from "cities" where "is_active" = $1 ^ HINT: No operator matches the given name and argument types. You might need to add explicit type casts. (SQL: select * from "cities" where "is_active" = 1)

Why does it cast the field from boolean to integer? As you see, I explicitly passed true in second argument but Laravel converts the value to 1 and Postgres returns an error. However, when I run the raw query with "is_active = true" it works.

2

2 Answers

3
votes
City::where('is_active','=' ,'true')->get();
2
votes

This was caused by an update to php 8.0.5. You need to downgrade to PHP 8.0.4 or wait for 8.0.6. https://github.com/laravel/framework/issues/37215