samedi 29 août 2015

Laravel 5 query `LIKE` issue

I have a special_number table with a prefix column. The column contains 022,021 etc data. I have a number 0216627363021. How I match the column using LIKE keyword to get the row.

$rate = Special::where('user_id',$user_id)
            ->where(DB::raw("prefix LIKE $number"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-1)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-2)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-3)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-4)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-5)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-6)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-7)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-8)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-9)"))
            ->orWhere(DB::raw("prefix LIKE SUBSTR($number,1,-10)"))
            ->first();

but it return NULL. Where is the problem? Thank you.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1F5XR8a
via IFTTT

Aucun commentaire:

Enregistrer un commentaire