How can I do a type cast for comparing values in Laravel Fluent? For example if I have the following MySQL:
SELECT * from table1 WHERE CAST(`values` AS SIGNED) > $myVar
This is what I currently have after writing the above in Fluent:
$query = DB::connection('mysql')->table('table1')
->where('values', '>', $myVar);
Currently the database is treating this as a string. The column in the table needs to be kept as a varchar for other reasons. How can I do the type cast for this particular query in Laravel Fluent?
Untested, but I believe this should work:
$query = DB::connection('mysql')->table('table1')
->where(DB::raw('CAST(values AS SIGNED)'), '>', $myVar);
Also
$query= DB::connection('mysql')
->table('table1')
->whereRaw('CAST(values AS SIGNED) > '.$myVar);
works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With