StudentPolicy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A show() 0 5 1
1
<?php
2
3
namespace App\Models\Policies;
4
5
use App\Models\Student;
6
use App\Models\User;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class StudentPolicy
10
{
11
    use HandlesAuthorization;
12
13
    /**
14
     * Create a new policy instance.
15
     *
16
     * @return void
17
     */
18
    public function __construct()
19
    {
20
        //
21
    }
22
23
    /**
24
     * Determine if the given post can be updated by the user.
25
     */
26
    public function show(User $user, Student $student)
27
    {
28
        // if the student is enrolled in any class by the user
29
30
        return $student->enrollments()->whereHas('course', fn ($q) => $q->where('teacher_id', $user->id))->count() > 0;
31
    }
32
}
33