count(); $query->where( function ($q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } } ); $count = $query->count(); $set = $query->get(); /* * Build something with JSON? */ return $set; } }