简体   繁体   中英

how can i write this sql in laravel eloquent

This SQL is working fine in mysql for testing purpose, i am getting the street_address_extracted from it

select *, regexp_substr(trim(street_address), '^\\d+\\s+\\w+') street_address_extracted from user_listings WHERE is_found_before = 0

But when i run this query in laravel as i don't get the street_address_extracted field results its always blank but when manually raun into phpmyadmin i get 1000s of rows.

Here is how i wrote this into laravel

DB::select(DB::raw("select *, regexp_substr(trim(street_address), '^\\d+\\s+\\w+') street_address_extracted from user_listings WHERE is_found_before = 0"));

street_address_extracted 为空

when ran manually in phpmyadmin i get this. 在此处输入图片说明

Try this -

DB::table('user_listings')
    ->selectRaw("*, regexp_substr(trim(street_address), '^\\d+\\s+\\w+') AS street_address_extracted")
    ->where('is_found_before', 0)
    ->get();

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