Passed
Push — master ( 1d6548...c98942 )
by Julien
29:57
created

Competitor::fightersGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Xoco70\KendoTournaments\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Foundation\Auth\User;
8
9
class Competitor extends Fighter
10
{
11
    use SoftDeletes;
12
    protected $DATES = ['created_at', 'updated_at', 'deleted_at'];
13
14
    protected $table = 'competitor';
15
    public $timestamps = true;
16
    protected $fillable = [
17
        'tournament_category_id',
18
        'user_id',
19
        'confirmed',
20
    ];
21
22
    /**
23
     * Get User from Competitor.
24
     *
25
     * @return mixed
26
     */
27
    public function user()
28
    {
29
        return $this->belongsTo(User::class);
30
    }
31
32
    /**
33
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
34
     */
35
    public function fightersGroups()
36
    {
37
        return $this->belongsToMany(FightersGroup::class, 'fighters_group_competitor')->withTimestamps();
38
    }
39
40
    /**
41
     * @return null|string
42
     */
43
    public function getName()
44
    {
45
        return $this->defaultName() ?? $this->user->name;
46
    }
47
48
    /**
49
     * @return null|string
50
     */
51
    public function getFullName()
52
    {
53
        return $this->defaultName() ?? $this->user->firstname . " " . $this->user->lastname;
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59
    private function defaultName()
60
    {
61
        if ($this == null || $this->user == null) return "BYE";
62
        return null;
63
    }
64
65
}
66