Querying VARCHAR column using PHP integer value in the Query Builder #38712
Unanswered
pratheepbg-dckap
asked this question in
Q&A
Replies: 1 comment
-
I also facing this issue a long time back. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description:
Greetings Artisans !!!
When Querying a database table on a
VARCHAR
column with aninteger
value in the Query Builder, the SQL query is created likecolumn = 1
while querying the Database.This is resulting in the records that starts with the same characters in that number
we are getting results with the values like
1527
,1527-1
& so on. This causes problem when mixed with->orderBy()
and getting single record using->first()
and messes with the Computation.This can be solved by passing
string
type in thewhere
method like->where('varchar_column', '=', (string) 1527)
.Is there any possible ways for Laravel to determine Column type and performing the casting automatically?
Steps To Reproduce:
1527
,1527-1
,1527-a1
& so on for the Varchar column.where
constraint providing PHP integer valueBeta Was this translation helpful? Give feedback.
All reactions