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

afoysal's avatar

Query not meeting requirement

My Query is like below

$addressess = Address::where('first_name', 'LIKE', $request->letter.'%')->where('user_id', Auth::id())->get();

My Table is like below

Table

My result is like below

Result

Why I am not getting all the records of user_id 1 ?

I am getting 1 record less.

0 likes
5 replies
MarianoMoreyra's avatar

Hi @afoysal

Are you sure that the result is wrong? Can you do a dd($request->letter) before the query to check how are you filtering?

It seems to me that you might be passing a 'c' on $request->letter in which case the result is perfect.

1 like
afoysal's avatar

Thanks @marianomoreyra for your reply. Yes, I am passing 'c' on $request->letter. I can see user id 1 in user_id column 4 times. But I am getting 3 records. Why I am getting 3 records ? I should get 4 records. Thanks.

MarianoMoreyra's avatar
Level 25

@afoysal you have 4 records with that user_id but your query is asking for those with user_id = 1 AND with first_name starting with that letter 'c'

So, in this case, 1 of those 4 records doesn't meet the criteria as the name is 'Paul', which starts with a 'P' and not a 'c'.

1 like

Please or to participate in this conversation.