To make one Laravel query compare a MySQL string case-sensitively, use whereBinary(), available in the Laravel version that includes the method. It makes the comparison byte-sensitive, rather than changing how the column behaves everywhere. If case-sensitive comparison is a lasting rule for a column, a suitable column collation may be a better fit.
How do I make a Laravel MySQL query case-sensitive?
Use Laravel’s query builder to apply a binary comparison to the equality condition:
As an Amazon Associate I earn from qualifying purchases.
DB::table('invites')
->whereBinary('token', $request->token)
->first();
Laravel’s MySQL grammar compiles this clause as an equality comparison using binary. The value remains a query-builder binding; do not interpolate request input into a raw SQL string. The framework’s MySQL grammar source shows how the MySQL clause is compiled.
The whereBinary() method family is reported as introduced in Laravel 13.27 by Laravel News. That version claim is secondary reporting, not an independently verified official release note. Check the installed framework version and its query-builder documentation before using it. Related methods include whereNotBinary() for inequality and orWhereBinary() or orWhereNotBinary() for disjunctive conditions.
#1 Best Overall
Why ordinary string equality may ignore case
MySQL’s comparison behavior depends on the collations of the comparison operands. The MySQL 26.7 Reference Manual explains that searches on nonbinary CHAR, VARCHAR, and TEXT strings use the operands’ collation. Under a collation where characters share a sort value, strings differing in case can compare equal.
There is no safe basis for assuming every deployed MySQL database uses one universal case-insensitive default: server version, database and column definitions, and explicit collations can change behavior. The cited manual identifies utf8mb4_0900_ai_ci as its default character set and collation in that documentation; inspect the actual schema and server version when diagnosing a query.
What “binary” changes—and what it does not
MySQL compares binary strings by the numeric values of their bytes. For alphabetic characters this makes comparisons case-sensitive, but the comparison is not limited to letter case: accents and distinct byte sequences can also produce different results. Byte-sensitive comparison may therefore be stricter than an application’s intended notion of “same text,” particularly when text can have different Unicode representations.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →whereBinary() addresses an equality condition. For wildcard pattern matching, Laravel’s query builder has whereLike() with a case-sensitive option in supported contexts. Consult the Laravel query documentation and confirm support for the database driver in use; pattern matching and equality are separate requirements.
Rank #3
Choose the scope that matches the rule
| Requirement | Approach | What to consider |
|---|---|---|
| One equality lookup must distinguish case or bytes | whereBinary() with the MySQL grammar |
Applies to that predicate; verify the method exists in the installed Laravel version and check the resulting query plan. |
| Comparisons for a column should consistently be case-sensitive | Give the column a suitable case-sensitive or binary collation | Changes comparison behavior beyond one read query. Review existing data, uniqueness rules, and migration impact. |
| A wildcard pattern must be case-sensitive | whereLike() with its case-sensitive option where supported |
Driver support matters; this is pattern matching, not binary equality. |
MySQL explicitly recommends declaring a column with a case-sensitive or binary collation when it should always be treated case-sensitively. That schema-level rule is broader than a query-specific predicate. In particular, uniqueness follows the column’s collation, not a read-side whereBinary() condition, so assess the application’s existing data and unique constraints before changing a column.
Check driver support and index behavior
The implementation evidence establishes compilation by Laravel’s MySQL grammar; it does not establish uniform behavior across every Laravel database driver. Do not assume the method is portable without confirming support for the driver and framework version used by your application.
Rank #4
A binary predicate may not align with an index defined under the column’s collation. Laravel News discusses combining a regular indexed predicate with binary filtering as a possible approach, but that is not a guaranteed optimization across MySQL versions or schemas. Use EXPLAIN on the actual query and validate performance against representative data and workload before changing the query for index reasons.
Free tools Windows power users keep installed
One-click scans. No signup required.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




