Passed
Pull Request — master (#17)
by Stephen
08:18 queued 04:17
created

Team::newFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
    ];
47
48
    /**
49
     * The attributes that should type cast.
50
     *
51
     * @var array
52
     */
53
    protected $casts = [
54
        'team_id' => 'int',
55
        'user_id' => 'int',
56
        'order' => 'int',
57
    ];
58
59
    /**
60
     * Create a new factory instance for the model.
61
     *
62
     * @return TeamFactory
63
     */
64
    protected static function newFactory(): TeamFactory
65
    {
66
        return new TeamFactory();
67
    }
68
69
    /**
70
     * Team member's 'user' relationship.
71
     *
72
     * @return BelongsTo
73
     */
74
    public function user()
75
    {
76
        return $this->belongsTo(User::class, 'user_id', 'id')
77
            ->withoutGlobalScope(UserActiveScope::class);
78
    }
79
}
80