简体   繁体   中英

How to use REPLACE with WhereRaw eloquent laravel?

I have a column in my database that saved with double quotation (") now I want to replace it by space.I'm using REPLACE and whereRaw.but It dosent work. this is my code:

 $query->whereRaw("trim(REPLACE(name),'\"','') ='.trim($name).'")

actually using / for scaping (").Any Idea?

I believe you found the answer in the comments another thing what I suggest is don't append the value directly since this may lead to sql injection what I suggest you to use in ? operator something like this

$query->whereRaw("trim(REPLACE(name),'\"','') = ? ",[trim($name)])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM