简体   繁体   中英

Convert sql query to eloquent

I'm trying to convert a query to a Laravel query but when I use raw method I can't make it work.

My query:

SELECT * FROM leagues
   WHERE SOUNDEX(name) 
      LIKE CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%');

I couldn't find any docs online that answer me.

You can use WhereRaw() to conver this query to Laravel Query Builder.

DB::table('leagues')
  ->whereRaw("SOUNDEX(name) 
             LIKE CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%')");

if you don't prefer WhereRaw() then you have to use DB::raw() in your Conditions

DB::table('leagues')
  ->where( DB::raw('SOUNDEX(name)'), 'LIKE', DB::raw("CONCAT('%',SUBSTRING(SOUNDEX('Eng. Premier League'),5),'%')") ); 

Hope this helps.

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