Home > Backend Development > PHP Tutorial > How to Use the LIKE Operator for Searching in Laravel-5 Eloquent?

How to Use the LIKE Operator for Searching in Laravel-5 Eloquent?

Patricia Arquette
Release: 2024-10-29 03:50:29
Original
813 people have browsed it

How to Use the LIKE Operator for Searching in Laravel-5 Eloquent?

Laravel-5 Equivalent of 'LIKE' Operator (Eloquent)

In Laravel-5, the Eloquent ORM provides a designated operator for searching using the LIKE statement. However, the code provided in the question employs the 'orWhereLike' method, which is not recognized in Laravel-5.

To achieve the desired result, a combination of 'orWhere' with 'like' should be used:

<code class="php">BookingDates::where('email', Input::get('email'))
    ->orWhere('name', 'like', '%' . Input::get('name') . '%')->get();</code>
Copy after login

In terms of SQL, the above code produces the following statement:

<code class="sql">select * from booking_dates where email='[email protected]' or name like '%John%'</code>
Copy after login

To verify the generated SQL statement, you can use the dd(DB::getQueryLog()) function, which logs all executed queries and allows you to inspect their content during development.

The above is the detailed content of How to Use the LIKE Operator for Searching in Laravel-5 Eloquent?. 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