lundi 17 août 2020

Laravel 7 / SQL case insensitive where clause

Have a problem on getting data from the DB. The problem is, that the search query uses case sensitive parameters, which I don't want.

Need a solution, to find all database fields without case sensitivity and exactly as the string is, no text after, and before.

Example:

First I get the data: $affiliateOpens = AffiliateOpen::where('user_id', $user->id)->get();

Then, I convert the strings I will be searching throught to lowercase, like so (Because there are many records with different charachter cases:

$sources = [];
    foreach ($affiliateOpensCollection  as $affiliateOpen)
        $sources[] = strtolower($affiliateOpen->source);

 foreach ($uniqueSources as $source) {
        $sourceData[$source]['installs'] = count($affiliatesOpenCollection->where('source', $source)->where('date_installed', '<>', null));
 }

How could I search without case sensitivity and get the data from the database?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire