Product::where('name', 'like', 'something%')->orWhere('category', 'like', 'something%')->orWhere('price', 'like', 'something%')->orWhere('qty', 'like', 'something%')...
Can I do it in more elegant and compact way?
You can use 'array_map()' to build an array for orWhere():
$search = 'something';
Product::orWhere(array_map(
function ($i) use($search) { return [$i, 'like', $search.'%']; },
['name', 'category', 'price', 'qty']
))->get();
It's a good way if you have many fields to search by. For 3-4 fields, I'd just use simple orWhere() chaining, because it's easier to read the code