October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Laravel’s whereBinary(): Case-Sensitive MySQL Queries

Use Laravel’s whereBinary() for a byte-sensitive MySQL equality lookup. Learn how collation affects ordinary comparisons and when a column-level rule is more appropriate.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.