Passed
Pull Request — develop (#11)
by
unknown
03:46 queued 56s
created

Membership::student()   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 App\Judite\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Membership extends Model
8
{
9
    /**
10
     * The relations to eager load on every query.
11
     *
12
     * @var array
13
     */
14
    protected $with = ['student', 'group'];
15
16
    /**
17
     * Scope a query to filter memberships by owner.
18
     *
19
     * @param \Illuminate\Database\Eloquent\Builder $query
20
     * @param \App\Judite\Models\Student            $student
21
     *
22
     * @return \Illuminate\Database\Eloquent\Builder
23
     */
24
    public function scopeOwnedBy($query, Student $student)
25
    {
26
        return $query->whereStudentId($student->id);
27
    }
28
29
    /**
30
     * Scope a query to order memberships by students number.
31
     *
32
     * @param \Illuminate\Database\Eloquent\Builder $query
33
     *
34
     * @return \Illuminate\Database\Eloquent\Builder
35
     */
36
    public function scopeOrderByStudent($query)
37
    {
38
        return $query->select('memberships.*')
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->select('m...student_number', 'asc') also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
39
            ->join('students', 'memberships.student_id', '=', 'students.id')
40
            ->orderBy('students.student_number', 'asc');
41
    }
42
43
    /**
44
     * Get student of this membership.
45
     *
46
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
47
     */
48
    public function student()
49
    {
50
        return $this->belongsTo(Student::class);
51
    }
52
53
    /**
54
     * Get group of this membership.
55
     *
56
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
57
     */
58
    public function group()
59
    {
60
        return $this->belongsTo(Group::class);
61
    }
62
}
63