Answer the question
In order to leave comments, you need to log in
Search ID like '11'?
I know how to do it on pure PG: CAST (id as text ) LIKE '11'
In Laravel this does not work, I indicated in the class:
protected $casts = [
'product_id' => 'string', // text ムひセミカミオ ミソムミセミアミセミイミーミサ
];
// ムひセミカミオ ミスミオ ムミーミアミセムひーミオム
DB::select('SELECT * FROM products WHERE CAST(product_id AS TEXT) LIKE 10');
//ムひーミコムτ
FatalThrowableError in ProductController.php line 111:
Parse error: syntax error, unexpected as (T_AS), expecting ',' or ')'
in ProductController.php line 111
at Composer\Autoload\includeFile('C:\Users\BonBonS\Desktop\OpenServerUltimate\domains\market\vendor\composer/../../app/Http/Controllers/ProductController.php') in ClassLoader.php line 301........
// ミクミサミク
QueryException in Connection.php line 770:
SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: integer ~~ unknown
LINE 1: select * from "products" where "product_id" LIKE $1 limit 1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. (SQL: select * from "products" where "product_id" LIKE %11% limit 1)
in Connection.php line 770
at Connection->runQueryCallback('select * from "products" where "product_id" LIKE ? limit 1', array('%11%'), object(Closure)) in Connection.php line 726
// ミ寅エミオ ムミーミシミーム ミウミサミーミイミスミーム ムミームムび ム采ひセ:
- operator does not exist: integer ~~ unknown
- add explicit type casts
Answer the question
In order to leave comments, you need to log in
The expression after LIKE must be in quotes. You can use $$ instead of single quotes
DB::select('SELECT * FROM products WHERE CAST(product_id AS TEXT) LIKE $$10$$');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question