Laravel-5 'LIKE' Equivalent (Eloquent)
When utilizing Eloquent in Laravel 5, the "LIKE" operator can be replicated by using the "orWhereLike" method. However, if this method fails to yield the desired results, it's helpful to comprehend the MySQL statement it triggers.
In the provided code:
BookingDates::where('email', Input::get('email'))->orWhere('name', 'like', Input::get('name'))->get()
The corresponding MySQL statement would resemble:
select * from booking_dates where email='[email protected]' or name like Input::get('name');
To accurately mimic the desired query:
select * from booking_dates where email='[email protected]' or name like '%John%'
Employ percent symbols ("%") around the search parameter as demonstrated below:
BookingDates::where('email', Input::get('email')) ->orWhere('name', 'like', '%' . Input::get('name') . '%')->get();
The above is the detailed content of How Can I Use the `LIKE` Operator with Eloquent in Laravel 5?. For more information, please follow other related articles on the PHP Chinese website!