Laravel-5 'Like' Equivalent (Eloquent)

Laravel-5 'LIKE' equivalent (Eloquent)

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();

Laravel eloquent multiple WHERE with OR AND OR and LIKE?

Use like and not like with % in where() and orWhere() methods:

->where('column', 'like', '%pattern%')

https://laravel.com/docs/5.3/queries#where-clauses

If you need to use multiple AND do like this:

->where($condition)
->where($anotherCondition)

If you want to use OR do this:

->where($condition)
->orWhere($anotherCondition)

To combine multiple AND and OR do parameter grouping:

->where('name', '=', 'John')
->orWhere(function ($query) {
$query->where('votes', '>', 100)
->where('title', '<>', 'Admin');
})

Laravel 5: How to use 'where' or 'orderBy' using eloquent?

You can do it like this:

$ideas = $user->idea()
->where('status', '<>', 'DRAFT')
->orderBy('created_at', 'desc')
->get();

When you use ->idea() it will start a query.

For more information about how to query a relationship: https://laravel.com/docs/5.7/eloquent-relationships#querying-relations

laravel querybuilder how to use like in wherein function

Thanks everyone for helping me but i solved it by doing:

$book = array('book2','book3','book5');  

$name = DB::Table('bookinfo')
->select('BookName', 'bookId')
->Where(function ($query) use($book) {
for ($i = 0; $i < count($book); $i++){
$query->orwhere('bookname', 'like', '%' . $book[$i] .'%');
}
})->get();


Related Topics



Leave a reply



Submit