Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

MySql then text searches by default are case insensitive. PostgreSQL I think you have to force it to lower.

I don't see anything in the API though for doing this, but you can control it in the MySql settings of laravel, again not sure about PostgreSQL

utf8_bin (default) case-insensitive

unicode_ci case-sensitive

Not sure how to go about it on a query by query basis though. I would suspect you need raw selects

DB:select('select * from table where lower(field) like "%?%"', array($value))
Last updated 1 year ago.
0

Thank you for your kind answer. I have not find relevant information either (not in the Laravel files either).

For obvious reasons I don't want to mess with the default case sensitivity. This was my solution, which is almost the same as yours:

$q->where( function ( $q2 ) use ( $stext ) {
	$q2->whereRaw( 'LOWER(`title`) like ?', array( $stext ) );
	$q2->orWhereRaw( 'LOWER(`desc`) like ?', array( $stext ) );
});
Last updated 1 year ago.
0

Maybe is too late, but if you don't want to use "LOWER", you could use "ILIKE". But it stills working at PostgresSql only.

$q->where( function ( $q2 ) use ( $stext ) {
	$q2->where( 'title', 'ilike', "%$stext%" ) );
	$q2->orWhere('desc', 'ilike', "%$stext%" ) );
});
0

Sign in to participate in this thread!

Eventy

Your banner here too?

orosznyet orosznyet Joined 6 Apr 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.