Ex: i want to get events which has category slug "entertainment" . How to do that dynamically?
Product::with('Categories')->whereHas('categories', function ($query) use ($categoryName) {
$query->where('category_name', $categoryName);
})->orderBy('id','DESC')->get();
if i use whereHas it will scan full table. will it affect the performance if my table has 10000 records for each category?
Affect performance compared to what? More complex queries are slower, but there is no faster way to do it if that is what you are asking.