Passed
Push — master ( a958bc...8e2bab )
by Ron
01:34
created

World::scopeOnlineCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Starpeace\Models\Eloquent\Common;
4
5
use Starpeace\Models\Eloquent\BaseModel;
6
7
class World extends BaseModel
8
{
9
    protected $table = 'worlds';
10
11
    protected $fillable = [ 'galaxy_id', 'map_id', 'name', 'display_name', 'use_whitelist', 'use_blacklist' ];
12
13
    protected $dates = [ 'created_at', 'updated_at' ];
14
15
    public function galaxy()
16
    {
17
        return $this->belongsTo(Galaxy::class, 'id', 'galaxy_id');
18
    }
19
20
    public function tycoons()
21
    {
22
        return $this->hasMany(WorldTycoon::class);
23
    }
24
25
    public function worldTycoons()
26
    {
27
        return $this->hasMany(WorldTycoon::class);
28
    }
29
30
    public function online()
31
    {
32
        return $this->hasMany(WorldTycoon::class);
33
    }
34
35
    public function investors()
36
    {
37
        return $this->hasMany(WorldTycoon::class);
38
    }
39
40
    public function scopeOnlineCount($query)
41
    {
42
        return $query->withCount(['online' => function ($query) {
43
            $query->online();
44
        }]);
45
    }
46
47
    public function scopeInvestorCount($query)
48
    {
49
        return $query->withCount('investors');
50
    }
51
}
52