Commit 19f4498c authored by Ricardo Walter Hildebrand's avatar Ricardo Walter Hildebrand
Browse files

incluindo contagem de materials e trilhas

parent 1f635b88
Pipeline #4210 passed with stages
in 5 minutes and 52 seconds
......@@ -18,6 +18,22 @@ class PartnerController extends Controller
$fields = [
'partners.*',
\DB::raw('(
SELECT
COUNT(material_partner.material_id)
FROM material_partner
WHERE 1 = 1
AND material_partner.partner_id = partners.id
) AS materials_count'),
\DB::raw('(
SELECT
COUNT(partner_trail.trail_id)
FROM partner_trail
WHERE 1 = 1
AND partner_trail.partner_id = partners.id
) AS trails_count'),
\DB::raw('(
SELECT
COUNT(formations.id)
......
......@@ -45,6 +45,12 @@ class Partner extends JsonResource
$data['trails'] = new TrailCollection($this->trails);
}
if (isset($this->materials_count)) {
$data['materials_count'] = (int) $this->materials_count;
}
if (isset($this->trails_count)) {
$data['trails_count'] = (int) $this->trails_count;
}
if (isset($this->formations_count)) {
$data['formations_count'] = (int) $this->formations_count;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment