1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\Customer; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use App\Models\UserRolePermissions; |
8
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
9
|
|
|
|
10
|
|
|
class CustomerPolicy |
11
|
|
|
{ |
12
|
|
|
use HandlesAuthorization; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Determine whether the user can view any models. |
16
|
|
|
* |
17
|
|
|
* @param \App\Models\User $user |
18
|
|
|
* @return mixed |
19
|
|
|
*/ |
20
|
|
|
public function viewAny(User $user) |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
// |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Determine whether the user can view the model. |
27
|
|
|
* |
28
|
|
|
* @param \App\Models\User $user |
29
|
|
|
* @param \App\Models\Customer $customer |
30
|
|
|
* @return mixed |
31
|
|
|
*/ |
32
|
|
|
public function view(User $user, Customer $customer) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
// |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Determine whether the user can create models. |
39
|
|
|
* |
40
|
|
|
* @param \App\Models\User $user |
41
|
|
|
* @return mixed |
42
|
|
|
*/ |
43
|
|
|
public function create(User $user) |
44
|
|
|
{ |
45
|
|
|
$allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q) |
46
|
|
|
{ |
47
|
|
|
$q->where('description', 'Add Customer'); |
48
|
|
|
})->first(); |
49
|
|
|
|
50
|
|
|
if($allowed) |
51
|
|
|
{ |
52
|
|
|
return $allowed->allow; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Determine whether the user can update the model. |
60
|
|
|
* |
61
|
|
|
* @param \App\Models\User $user |
62
|
|
|
* @param \App\Models\Customer $customer |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function update(User $user, Customer $customer) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q) |
68
|
|
|
{ |
69
|
|
|
$q->where('description', 'Update Customer'); |
70
|
|
|
})->first(); |
71
|
|
|
|
72
|
|
|
if($allowed) |
73
|
|
|
{ |
74
|
|
|
return $allowed->allow; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Determine whether the user can delete the model. |
82
|
|
|
* |
83
|
|
|
* @param \App\Models\User $user |
84
|
|
|
* @param \App\Models\Customer $customer |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function delete(User $user, Customer $customer) |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
// |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Determine whether the user can restore the model. |
94
|
|
|
* |
95
|
|
|
* @param \App\Models\User $user |
96
|
|
|
* @param \App\Models\Customer $customer |
97
|
|
|
* @return mixed |
98
|
|
|
*/ |
99
|
|
|
public function restore(User $user, Customer $customer) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
// |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Determine whether the user can permanently delete the model. |
106
|
|
|
* |
107
|
|
|
* @param \App\Models\User $user |
108
|
|
|
* @param \App\Models\Customer $customer |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function forceDelete(User $user, Customer $customer) |
|
|
|
|
112
|
|
|
{ |
113
|
|
|
// |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.