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
Release: 2024-11-27 01:07:09
Original
874 people have browsed it

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%')
Copy after login

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();
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template