i want to apply keyword searching on products that is child of categories table. categories table is parent and products table is child and both having hasMany relationship.
$terms = explode(" ", $req->searchInput);
$result= $categories->query()
->whereHas('products', function ($query) use ($terms) {
foreach ($terms as $term) {
// Loop over the terms and do a search for each.
$query->where('name', 'like', '%' . $term . '%');
}
return $query;
})->get();