blob: 72d8079e17810790aad124bc2039440faa662bdb (
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
58
59
60
61
62
63
64
65
66
67
|
<?php
namespace App\Policies;
use App\Models\Admin;
use App\Models\Appointment;
use App\Models\Company;
use App\Models\Student;
class AppointmentPolicy
{
public function create($user): bool
{
return $this->isStudent($user);
}
protected function isStudent($user): bool
{
return $user instanceof Student;
}
public function viewAny($user): bool
{
return $this->isAdmin($user);
}
protected function isAdmin($user): bool
{
return $user instanceof Admin;
}
public function view($user, Appointment $appointment): bool
{
return $this->isRelatedToAppointment($user, $appointment) || $this->isAdmin($user);
}
protected function isRelatedToAppointment($user, Appointment $appointment): bool
{
return $user->id === $appointment->student_id ||
$user->id === $appointment->company_id;
}
public function update($user, Appointment $appointment): bool
{
return $this->isRelatedToAppointment($user, $appointment) || $this->isAdmin($user);
}
public function delete($user, Appointment $appointment): bool
{
return $this->isRelatedToAppointment($user, $appointment) || $this->isAdmin($user);
}
public function restore($user, Appointment $appointment): bool
{
return false;
}
public function forceDelete($user, Appointment $appointment): bool
{
return false;
}
protected function isCompany($user): bool
{
return $user instanceof Company;
}
}
|