Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 4 months ago.
0

you can try to remove whitespace and add simply your code

$jobs->where('CollPCode','LIKE','%'.$colpostcode.'%')
        ->orWhere('CollPCode','LIKE','%'.preg_replace('/\s+/', '', $colpostcode).'%');
Last updated 7 years ago.
0

Hey , Thanks but I do not think this works in both situations. For example if the DB entry has a space "B37 7GT" , then if user searches "B377GT" it will not find the version with a space in the DB? I need to strip the DB version of whitespaces on the where also no?

0

you dont want a like, you need a regexp something like:

select 'b377gt' REGEXP '[[:alnum:]][[:blank:]]*[[:alnum:]]{3}';

so it will match both with/without spaces

0

Thanks Shez, how would i put that into a query?

 if(!empty($ColDate)){
                $jobs->where('ColDate',$ColDate);
            }
Last updated 7 years ago.
0

$jobs->where('CollPCode','LIKE','%'.$colpostcode.'%');

should be: $jobs->where('CollPCode','REGEXP','pattern');

0

use replace, $jobs->orWhereRaw('REPLACE (CollPCode," ","") LIKE "%'.str_replace(' ','%',$colpostcode).'%"')

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

scotchegg scotchegg Joined 4 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.