Home >Backend Development >PHP Tutorial >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>
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>
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!