Sort resource by relationship count – exception when empty

I have Developers that own Software and I'm currently using $table->defaultSort('software_count', 'desc') to sort my developers by the amount of software they have on my DeveloperResource.

If a developer does not have any software, I get an SQL exception for Unknown column 'software_count' in 'order clause'

Is there any way around that? It's just a simple HasMany relationship.

I get this same issue with Tables\Columns\TextColumn::make('software_count') but I think I can maybe do a hidden() conditional check on it or something – but I also feel like I might be missing something. Ideally it'd just default to 0.
Was this page helpful?