Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cooperino's avatar

Simple query returns empty array no matter what

I have a simple query:

ItemsList::query()->where('account_id', '==', $this->user()->account_id)->get();

But I always get

Illuminate\Database\Eloquent\Collection {#1952
  #items: []
  #escapeWhenCastingToString: false
}

I checked and $this->user()->account_id returns the correct id, and in the table that corresponds to the model itemList there is definitely a column account_id and there is the correct id that is shown from the above command ($this->user()->account_id)

0 likes
5 replies
Sinnbeck's avatar

Use debugbar to see what query is actually being run

1 like
cooperino's avatar

@Sinnbeck I used mySql() instead and this is the query:

`"select * from `items_list` where `account_id` = ? and `items_list`.`deleted_at` is null"`

what? how?

Edit: It should still work because I really need to check that deleted_at is null. But it's still not working

Sinnbeck's avatar

@cooperino and if you hardcode the id?

ItemsList::query()->where('account_id', '=', 22)->get(); 
1 like
cooperino's avatar

@Sinnbeck apparently the error was due to double equal signs: ==. I changed it to = and it worked!

Sinnbeck's avatar

@cooperino according to your previous post, laravel had fixed your double=. Check your own post above. Does it break instantly if you change it back?

It was why I suggested checking with debug bar

Please or to participate in this conversation.