Laravel-5 'LIKE' equivalent (Eloquent)

V4n1ll4 picture V4n1ll4 · Jun 10, 2015 · Viewed 332.6k times · Source

I'm using the below code to pull some results from the database with Laravel 5.

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

However, the orWhereLike doesn't seem to be matching any results. What does that code produce in terms of MySQL statements?

I'm trying to achieve something like the following:

select * from booking_dates where email='[email protected]' or name like '%John%'

Answer

Pawel Bieszczad picture Pawel Bieszczad · Jun 10, 2015

If you want to see what is run in the database use dd(DB::getQueryLog()) to see what queries were run.

Try this

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