Olá pessoal.
Estou com um problema na hora de pegar o return de uma função, alguém consegue me ajudar?
<?php
namespace App\Services\Reports;
use App\Helpers\IsUuid;
use App\Models\Subject;
use App\Models\ActivityLog;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
class CommunityStatusService
{
public function getRegularity(string $classId, int $cycleIs): ?Collection
{
if (!IsUuid::isValidUuid($classId)) {
return null;
}
$subjectData = Subject::query()
->with([
'subareas' => fn($query) => $query
->join('subarea_classes', 'subarea_classes.subarea_id', '=', 'subareas.id')
->with([
'activities' => fn($query) => $query
->withCount([
'activityStudent' => fn($query) => $query->where('already_know', true)
])
->withCount([
'timer' => fn($query) => $query->where('timers.concluded_at', '<>', null)
])
->where('activities.is_exam', false)
])
->where('subarea_classes.cycle_is', $cycleIs)
->where('subarea_classes.class_id', $classId)
->where('subarea_classes.active', true)
->orderBy('subarea_classes.cycle_is')
->orderBy('subarea_classes.week_is')
])
->orderBy('subjects.name')
->get();
//return $subjectData;
return $this->getTotalActivities($subjectData);
}
private function getTotalActivities($subjectData): int
{
$total = 0;
$totalAlreadyKnowOrConcludedAt = 0;
foreach ($subjectData as $subject) {
foreach ($subject->subareas as $item) {
$total += $item['activities_count'];
foreach ($item->activities as $activity) {
if ($activity['activity_student_count'] > 0 || $activity['timer_count'] > 0 ) {
$totalAlreadyKnowOrConcludedAt += 1;
}
}
}
}
return $total;
}
}
Utilizando o Insomnia, ao testar a rota, ele da o seguinte erro:
"message": "Return value of App\Services\Reports\CommunityStatusService::getRegularity() must be an instance of Illuminate\Database\Eloquent\Collection or null, int returned"