Institution_class_grade   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
c 0
b 0
f 0
dl 0
loc 76
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A educationSubject() 0 3 1
A boot() 0 5 1
A getParallelClasses() 0 8 1
A classes() 0 2 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Webpatser\Uuid\Uuid;
7
8
class Institution_class_grade extends Base_Model  {
9
10
    /**
11
     * The database table used by the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'institution_class_grades';
16
17
    /**
18
     * Attributes that should be mass-assignable.
19
     *
20
     * @var array
21
     */
22
    protected $fillable = ['institution_class_id', 'education_grade_id', 'modified_user_id', 'modified', 'created_user_id', 'created'];
23
24
    /**
25
     * The attributes excluded from the model's JSON form.
26
     *
27
     * @var array
28
     */
29
    protected $hidden = [];
30
31
    /**
32
     * The attributes that should be casted to native types.
33
     *
34
     * @var array
35
     */
36
    protected $casts = [];
37
38
    /**
39
     * The attributes that should be mutated to dates.
40
     *
41
     * @var array
42
     */
43
    protected $dates = ['modified', 'created'];
44
45
    /**
46
     *
47
     * @return \Illuminate\Database\Eloquent\Relations\HasManyThrough
48
     */
49
    public function educationSubject(){
50
        return $this->hasManyThrough('App\Models\Education_grades_subject','App\Models\Institution_subject',
51
            'education_subject_id' ,'education_subject_id');
52
    }
53
54
    /**
55
     * @param $id
56
     * @param $educationGradeId
57
     * @param $institutionId
58
     * @return mixed
59
     */
60
    public function getParallelClasses($id, $educationGradeId, $institutionId)
61
    {
62
        return self::find($id)
63
            ->where('institution_grades.id', $id)
64
            ->where('institution_grades.education_grade_id', $educationGradeId)
65
            ->where('institution_grades.institution_id', $institutionId)
66
            ->join('institution_grades', 'institution_classes.id', '=', 'institution_grades.institution_class_id')
67
            ->get()->toArray();
68
    }
69
70
    public static function boot()
71
    {
72
        parent::boot();
73
        self::creating(function ($model) {
74
            $model->id = (string) Uuid::generate(4);
75
        });
76
    }
77
78
79
    /**
80
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
81
     */
82
    public function classes(){
83
        return $this->belongsTo('App\Models\Institution_grade','institution_class_id','id');
84
    }
85
}
86