Home >Database >Mysql Tutorial >How to Use the Laravel Eloquent Equivalent of MySQL\'s LIKE Operator?

How to Use the Laravel Eloquent Equivalent of MySQL\'s LIKE Operator?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-27 01:07:09875browse

How to Use the Laravel Eloquent Equivalent of MySQL's LIKE Operator?

Laravel Equivalent to 'LIKE' Operator in Eloquent

In Laravel 5, the equivalent of the 'LIKE' operator in MySQL is 'orWhereLike'. However, users may encounter issues when utilizing 'orWhereLike' to match results.

Correct Syntax

To accurately match results, ensure the 'orWhereLike' syntax follows this pattern:

Model::where('column_name', 'like', '%search_term%')

Example

In your specific case, to retrieve data similar to your MySQL statement, adjust your code as follows:

BookingDates::where('email', Input::get('email'))
    ->orWhere('name', 'like', '%' . Input::get('name') . '%')
    ->get();

Checking Queries

If you wish to verify the queries generated by Eloquent, employ the 'dd(DB::getQueryLog())' function to display the executed database queries.

The above is the detailed content of How to Use the Laravel Eloquent Equivalent of MySQL\'s LIKE Operator?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn