You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class MyRequest extends FormRequest
{
/** * Determine if the user is authorized to make this request. * * @return bool */publicfunctionauthorize()
{
return Gate::inspect('ticket-data', $this);
}
publicfunctionfailedAuthorization()
{
thrownewHttpResponseException(response()->json([
'message' => __('error.failed_authorization'),
'exception' => __('error.parameter_permissions_insufficient')
], Response::HTTP_UNAUTHORIZED));
}
}
This works in most cases. But if I do Response::deny('Reason for denying') in the Gate I won't be able to access the string "Reason for denying". I have a workaround but I suspect it could be done easier by simply passing Gate::inspect('ticket-data', $this) directly to failedAuthorization()
class ZammadAPICall extends FormRequest
{
private ?string$authorizationErrorMessage;
/** * Determine if the user is authorized to make this request. * * @return bool */publicfunctionauthorize()
{
$response = Gate::inspect('ticket-data', $this);
$this->authorizationErrorMessage = $response->message();
return$response->allowed();
}
publicfunctionfailedAuthorization()
{
thrownewHttpResponseException(response()->json([
'message' => __('error.failed_authorization'),
'exception' => __('error.parameter_permissions_insufficient', [
'message' => $this->authorizationErrorMessage
])
], Response::HTTP_UNAUTHORIZED));
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm have the following code:
This works in most cases. But if I do
Response::deny('Reason for denying')
in theGate
I won't be able to access the string "Reason for denying". I have a workaround but I suspect it could be done easier by simply passingGate::inspect('ticket-data', $this)
directly tofailedAuthorization()
Beta Was this translation helpful? Give feedback.
All reactions