Skip to content
Advertisement

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?

Advertisement

Answer

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)])
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement