Completed
Push — master ( 36889c...d49014 )
by Vincenzo
02:54
created

Player::goals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace App\Lib\DsManager\Models\Orm;
4
5
/**
6
 * Class Player
7
 * @package App\Lib\DsManager\Models
8
 */
9
class Player extends DsManagerOrm
10
{
11
12
    /**
13
     * @var string
14
     */
15
    protected $table = 'players';
16
17
    /**
18
     * @var array
19
     */
20
    protected $fillable = [
21
        'name',
22
        'surname',
23
        'age',
24
        'nationality',
25
        'skillAvg',
26
        'wageReq',
27
        'val',
28
        'role',
29
        'team_id'
30
    ];
31
32
    /**
33
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
34
     */
35
    public function team()
36
    {
37
        return $this->belongsTo(Team::class);
38
    }
39
40
    public function matches()
41
    {
42
        return $this->hasMany(MatchPlayer::class)
43
            ->orderBy('updated_at', 'DESC')
44
            ->limit(5);
45
    }
46
47
    public function goals()
48
    {
49
        return $this->hasOne(MatchPlayer::class)
50
            ->selectRaw('player_id, sum(goals) as count')
51
            ->groupBy('player_id');
52
    }
53
54
}