Sekolah::user()   A
last analyzed

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 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bantenprov\Sekolah\Models\Bantenprov\Sekolah;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Sekolah extends Model
9
{
10
    use SoftDeletes;
11
12
    public $timestamps = true;
13
14
    protected $table = 'sekolahs';
15
    protected $fillable = [
16
        'nama',
17
        'npsn',
18
        'jenis_sekolah_id',
19
        'alamat',
20
        'logo',
21
        'foto_gedung',
22
        'province_id',
23
        'city_id',
24
        'district_id',
25
        'village_id',
26
        'no_telp',
27
        'email',
28
        'kode_zona',
29
        'user_id',
30
    ];
31
    protected $hidden = [
32
    ];
33
    protected $appends = [
34
        'label',
35
        'jalur_umum',
36
        'jalur_prestasi',
37
        'jumlah_pendaftar',
38
    ];
39
    protected $dates = [
40
        'deleted_at',
41
    ];
42
43
    public function getLabelAttribute()
44
    {
45
        return $this->nama;
46
    }
47
48
    public function getJalurUmumAttribute()
49
    {
50
        return $this->siswas->whereIn('kegiatan_id', [11,21])->count();
51
    }
52
53
    public function getJalurPrestasiAttribute()
54
    {
55
        return $this->siswas->whereIn('kegiatan_id', [12,22])->count();
56
    }
57
58
    public function getJumlahPendaftarAttribute()
59
    {
60
        return $this->siswas->count();
61
    }
62
63
    public function user()
64
    {
65
        return $this->belongsTo('App\User', 'user_id');
66
    }
67
68
    public function jenis_sekolah()
69
    {
70
        return $this->belongsTo('Bantenprov\Sekolah\Models\Bantenprov\Sekolah\JenisSekolah', 'jenis_sekolah_id');
71
    }
72
73
    public function province()
74
    {
75
        return $this->belongsTo('Laravolt\Indonesia\Models\Province', 'province_id');
76
    }
77
78
    public function city()
79
    {
80
        return $this->belongsTo('Laravolt\Indonesia\Models\City', 'city_id');
81
    }
82
83
    public function district()
84
    {
85
        return $this->belongsTo('Laravolt\Indonesia\Models\District', 'district_id');
86
    }
87
88
    public function village()
89
    {
90
        return $this->belongsTo('Laravolt\Indonesia\Models\Village', 'village_id');
91
    }
92
93
    public function master_zona()
94
    {
95
        return $this->belongsTo('Bantenprov\Zona\Models\Bantenprov\Zona\MasterZona', 'kode_zona');
96
    }
97
98
    public function siswas()
99
    {
100
        return $this->hasMany('Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa', 'sekolah_id');
101
    }
102
}
103