aboutsummaryrefslogtreecommitdiffstats
path: root/source/app/Policies/StudentPolicy.php
blob: 633decdb29ddf92e14819e172c25d0667f8f51f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace App\Policies;

use App\Models\Admin;
use App\Models\Company;
use App\Models\Student;

class StudentPolicy
{
    public function viewAny($user): bool
    {
        return $user instanceof Admin || $user instanceof Company;
    }

    public function view($user, Student $student): bool
    {
        return $this->isAdmin($user)
            || ($user instanceof Company)
            || ($user instanceof Student && $user->id === $student->id);
    }

    protected function isAdmin($user): bool
    {
        return $user instanceof Admin;
    }

    public function create($user): bool
    {
        return $user instanceof Admin || $user instanceof Student;
    }

    public function update($user, Student $student): bool
    {
        return $this->isAdmin($user) || ($user instanceof Student && $user->id === $student->id);
    }

    public function delete($user, Student $student): bool
    {
        return $this->isAdmin($user) || ($user instanceof Student && $user->id === $student->id);
    }

    public function restore($user, Student $student): bool
    {
        return false;
    }

    public function forceDelete($user, Student $student): bool
    {
        return false;
    }

    public function verify($user, Student $student)
    {
        return $user instanceof Admin || $user->id === $student->id;
    }
}