12
12
namespace LaravelJsonApi \Core \Auth ;
13
13
14
14
use Illuminate \Contracts \Auth \Access \Gate ;
15
+ use Illuminate \Auth \Access \Response ;
15
16
use Illuminate \Http \Request ;
16
17
use LaravelJsonApi \Contracts \Auth \Authorizer as AuthorizerContract ;
17
18
use LaravelJsonApi \Contracts \Schema \Schema ;
@@ -47,10 +48,10 @@ public function __construct(Gate $gate, JsonApiService $service)
47
48
/**
48
49
* @inheritDoc
49
50
*/
50
- public function index (Request $ request , string $ modelClass ): bool
51
+ public function index (Request $ request , string $ modelClass ): bool | Response
51
52
{
52
53
if ($ this ->mustAuthorize ()) {
53
- return $ this ->gate ->check (
54
+ return $ this ->gate ->inspect (
54
55
'viewAny ' ,
55
56
$ modelClass
56
57
);
@@ -62,10 +63,10 @@ public function index(Request $request, string $modelClass): bool
62
63
/**
63
64
* @inheritDoc
64
65
*/
65
- public function store (Request $ request , string $ modelClass ): bool
66
+ public function store (Request $ request , string $ modelClass ): bool | Response
66
67
{
67
68
if ($ this ->mustAuthorize ()) {
68
- return $ this ->gate ->check (
69
+ return $ this ->gate ->inspect (
69
70
'create ' ,
70
71
$ modelClass
71
72
);
@@ -77,10 +78,10 @@ public function store(Request $request, string $modelClass): bool
77
78
/**
78
79
* @inheritDoc
79
80
*/
80
- public function show (Request $ request , object $ model ): bool
81
+ public function show (Request $ request , object $ model ): bool | Response
81
82
{
82
83
if ($ this ->mustAuthorize ()) {
83
- return $ this ->gate ->check (
84
+ return $ this ->gate ->inspect (
84
85
'view ' ,
85
86
$ model
86
87
);
@@ -92,10 +93,10 @@ public function show(Request $request, object $model): bool
92
93
/**
93
94
* @inheritDoc
94
95
*/
95
- public function update (Request $ request , object $ model ): bool
96
+ public function update (Request $ request , object $ model ): bool | Response
96
97
{
97
98
if ($ this ->mustAuthorize ()) {
98
- return $ this ->gate ->check (
99
+ return $ this ->gate ->inspect (
99
100
'update ' ,
100
101
$ model
101
102
);
@@ -107,10 +108,10 @@ public function update(Request $request, object $model): bool
107
108
/**
108
109
* @inheritDoc
109
110
*/
110
- public function destroy (Request $ request , object $ model ): bool
111
+ public function destroy (Request $ request , object $ model ): bool | Response
111
112
{
112
113
if ($ this ->mustAuthorize ()) {
113
- return $ this ->gate ->check (
114
+ return $ this ->gate ->inspect (
114
115
'delete ' ,
115
116
$ model
116
117
);
@@ -122,10 +123,10 @@ public function destroy(Request $request, object $model): bool
122
123
/**
123
124
* @inheritDoc
124
125
*/
125
- public function showRelated (Request $ request , object $ model , string $ fieldName ): bool
126
+ public function showRelated (Request $ request , object $ model , string $ fieldName ): bool | Response
126
127
{
127
128
if ($ this ->mustAuthorize ()) {
128
- return $ this ->gate ->check (
129
+ return $ this ->gate ->inspect (
129
130
'view ' . Str::classify ($ fieldName ),
130
131
$ model
131
132
);
@@ -137,18 +138,18 @@ public function showRelated(Request $request, object $model, string $fieldName):
137
138
/**
138
139
* @inheritDoc
139
140
*/
140
- public function showRelationship (Request $ request , object $ model , string $ fieldName ): bool
141
+ public function showRelationship (Request $ request , object $ model , string $ fieldName ): bool | Response
141
142
{
142
143
return $ this ->showRelated ($ request , $ model , $ fieldName );
143
144
}
144
145
145
146
/**
146
147
* @inheritDoc
147
148
*/
148
- public function updateRelationship (Request $ request , object $ model , string $ fieldName ): bool
149
+ public function updateRelationship (Request $ request , object $ model , string $ fieldName ): bool | Response
149
150
{
150
151
if ($ this ->mustAuthorize ()) {
151
- return $ this ->gate ->check (
152
+ return $ this ->gate ->inspect (
152
153
'update ' . Str::classify ($ fieldName ),
153
154
[$ model , $ this ->createRelation ($ request , $ fieldName )]
154
155
);
@@ -160,10 +161,10 @@ public function updateRelationship(Request $request, object $model, string $fiel
160
161
/**
161
162
* @inheritDoc
162
163
*/
163
- public function attachRelationship (Request $ request , object $ model , string $ fieldName ): bool
164
+ public function attachRelationship (Request $ request , object $ model , string $ fieldName ): bool | Response
164
165
{
165
166
if ($ this ->mustAuthorize ()) {
166
- return $ this ->gate ->check (
167
+ return $ this ->gate ->inspect (
167
168
'attach ' . Str::classify ($ fieldName ),
168
169
[$ model , $ this ->createRelation ($ request , $ fieldName )]
169
170
);
@@ -175,10 +176,10 @@ public function attachRelationship(Request $request, object $model, string $fiel
175
176
/**
176
177
* @inheritDoc
177
178
*/
178
- public function detachRelationship (Request $ request , object $ model , string $ fieldName ): bool
179
+ public function detachRelationship (Request $ request , object $ model , string $ fieldName ): bool | Response
179
180
{
180
181
if ($ this ->mustAuthorize ()) {
181
- return $ this ->gate ->check (
182
+ return $ this ->gate ->inspect (
182
183
'detach ' . Str::classify ($ fieldName ),
183
184
[$ model , $ this ->createRelation ($ request , $ fieldName )]
184
185
);
0 commit comments