I do like this.
public function toArray($request)
{
return parent::toArray($request);
}
And in the controller.
$rooms = new RoomCollection(
Room::
withCount('courses')
->orderBy('name')
->get()
);
And sure I have the JsonResource too.
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'can_update' => auth()->user()->can('update', $this->resource),
'can_delete' => auth()->user()->can('delete', $this->resource),
];
}