Reactable::getReactionsSummary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace FrancescoMalatesta\LaravelReactions\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphToMany;
7
8
trait Reactable
9
{
10
    /**
11
     * @return MorphToMany
12
     */
13
    public function reactions()
14
    {
15
        /** @var $this Model */
16
        return $this->morphToMany('FrancescoMalatesta\\LaravelReactions\\Models\\Reaction', 'reactable')
17
            ->withPivot(['responder_id', 'responder_type']);
18
    }
19
20
    /**
21
     * @return \Illuminate\Database\Eloquent\Collection|static[]
22
     */
23
    public function getReactionsSummary()
24
    {
25
        return $this->reactions()
26
            ->getQuery()
27
            ->select('name', \DB::raw('count(*) as count'))
28
            ->groupBy('name')
29
            ->get();
30
    }
31
}
32