Passed
Pull Request — master (#17)
by Stephen
14:26
created

Team::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Sfneal\Users\Models;
4
5
use Database\Factories\TeamFactory;
6
use Illuminate\Database\Eloquent\Factories\HasFactory;
7
use Illuminate\Database\Eloquent\Relations\BelongsTo;
8
use Sfneal\Models\Model;
9
use Sfneal\Models\Traits\CacheableAll;
10
use Sfneal\Scopes\OrderScope;
11
use Sfneal\Users\Scopes\UserActiveScope;
12
13
// todo: make use of this once sfneal/files packages is published
14
class Team extends Model
15
{
16
    use CacheableAll;
17
    use HasFactory;
18
19
    /**
20
     * The "booting" method of the model.
21
     *
22
     * @return void
23
     */
24
    protected static function boot()
25
    {
26
        parent::boot();
27
28
        // Query scopes
29
        static::addGlobalScope(new OrderScope('order', 'asc'));
30
    }
31
32
    protected $table = 'team';
33
    protected $primaryKey = 'team_id';
34
35
    protected $fillable = [
36
        'team_id',
37
        'user_id',
38
        'order',
39
    ];
40
41
    /**
42
     * @var array Relationships that should be eager loaded with every query
43
     */
44
    protected $with = [
45
        'user',
46
        'user.file',
47
    ];
48
49
    /**
50
     * The attributes that should type cast.
51
     *
52
     * @var array
53
     */
54
    protected $casts = [
55
        'team_id' => 'int',
56
        'user_id' => 'int',
57
        'order' => 'int',
58
    ];
59
60
    /**
61
     * Create a new factory instance for the model.
62
     *
63
     * @return TeamFactory
64
     */
65
    protected static function newFactory(): TeamFactory
66
    {
67
        return new TeamFactory();
68
    }
69
70
    /**
71
     * Team member's 'user' relationship.
72
     *
73
     * @return BelongsTo
74
     */
75
    public function user()
76
    {
77
        return $this->belongsTo(User::class, 'user_id', 'id')
78
            ->withoutGlobalScope(UserActiveScope::class);
79
    }
80
}
81