Search with multiple LIKE values with Laravel

Asked

Viewed 81 times

1

Good afternoon, I do a search using LIKE with Laravel in a table, but this search may require several values ex: %joão% %josé%, etc. but I’m not finding a way to do this search with various values in Laravel.

1 answer

1


The same way you do with where, only that using the orWhere this in a case of logical condition or, for example:

$users = DB::table('users')
                    ->where('name_1', 'like', '%thi%')
                    ->orWhere('name_2', 'like', '%John%')
                    ->get();

The only difference is that you use the orWhere.

Reference: https://laravel.com/docs/5.7/queries#Where-clauses

Browser other questions tagged

You are not signed in. Login or sign up in order to post.