want to do a search function, use multiple keywords to search the same field of the same model (such as description), each keyword search out a collection, these sets may have duplicate content, my idea is to merge these sets first. Then remove the duplicate information.
$search_key_array = explode(" ", $keyword);
//
$collection = collect([]);
foreach ($search_key_array as $value) {
$products = Product::where("description","like","%".$value."%")
->get();
if ($products->isNotEmpty()) {
$collection->concat($products);
}
}
//
$collection = $collection->unique()->values();
since I need an initial empty collection, I create it with collect () and append the searched collection to the empty collection using the concat method found in the document. As a result, I find that with this concat () method, there is no change in $conllection. Ask for help from the boss to see what the problem is?