@chaeril you're using pluck. Take a look here:
https://laravel.com/docs/10.x/collections#method-pluck
Pluck returns an array of only the plucked items. It defeats what you're trying to do.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I had a query like this, and Sentry detects it as an N+1 problem. what's the better way to do it?, I might use $appends but I don't want to count them everywhere I use the Brand model.
$this->brands = Brand::active()
->withCount(['ads' => function ($query) {
$query->active();
}])
->orderBy('ads_count', 'desc')
->orderBy('brand_name', 'asc')
->pluck('brand_name', 'brand_id')->sort();
Please or to participate in this conversation.