Rafael Furtado
Rafael Furtado

Reputation: 99

How to use (or) in laravel 6 for a query in the same table but in different columns?

How to perform queries in the Eloquent Laravel 6 database using "or" in columns of the same table?

Example: I want to search for the word "coffee" in the "products" table in name, description and ean1 columns. how do I do this using Eloquent?

Upvotes: 0

Views: 29

Answers (1)

Asif
Asif

Reputation: 350

You can do something like this:

$search_str = 'coffee'

$filter = Product::where('name', 'LIKE', '%' . $search_str . '%')->orWhere('description', 'LIKE', '%' . $search_str . '%')

Upvotes: 1

Related Questions