Is your feature request related to a problem? Please describe.
When permissions are denied using the built-in middlewares, there is no list of denied permissions/groups being passed on with the exception to the custom handler. I would like to catch them along with the 403 denied message.
Example:
Route::middleware('permissions:One', 'permissions:Two', 'permissions:Three')->group(function(){
Route::get('/', 'IndexController@index')->name('home');
});
When permissions One and Three gets denied, I would like the exception to show them.
Currently the exception is like below:
Junges\ACL\Exceptions\UnauthorizedException ~statusCode: 403~headers: Array(0)*message: "This user does not have the necessary permissions to access this route"...
~statusCode: 403
~headers: Array(0)
*message: "This user does not have the necessary permissions to access this route"
~string: ""
*code: 0
*file: "<application-path>\vendor\mateusjunges\laravel-acl\src\Exceptions\UnauthorizedException.php"
*line: 33
~trace: Array(43)
~previous: null
I would like it to be, for the above case : (refer after *message)
Junges\ACL\Exceptions\UnauthorizedException ~statusCode: 403~headers: Array(0)*message: "This user does not have the necessary permissions to access this route"...
~statusCode: 403
~headers: Array(0)
*message: "This user does not have the necessary permissions to access this route"
* denied : Array [
0: One
1: Three
]
~string: ""
*code: 0
*file: "<application-path>\vendor\mateusjunges\laravel-acl\src\Exceptions\UnauthorizedException.php"
*line: 33
~trace: Array(43)
~previous: null
Describe the solution you'd like
I have gone this far in catching the denied permissions list
PermissionMiddleware.php
public function handle($request, Closure $next, $permissions)
{
if (Auth::guest()) {
throw UnauthorizedException::notLoggedIn();
}
// New Array
$denied_permissions = [];
$permissions = is_array($permissions)
? $permissions
: explode('|', $permissions);
foreach ($permissions as $permission) {
if (Auth::user()->can($permission)) {
return $next($request);
} else {
array_push($denied_permissions, $permission);
}
}
throw UnauthorizedException::forPermissions($denied_permissions);
}
And, receiving it in
UnauthorizedException.php
public static function forPermissions($denied_permissions): self
{
$message = trans('acl::acl.forPermissions');
$denied = $denied_permissions;
return new static(Response::HTTP_FORBIDDEN, $message, null, $denied);
}
But, I am unable to pass it to the Laravel Response.
Describe alternatives you've considered
None.
I am not sure, this is the right approach. I tried some way to make it work for me.
This is my first time contributing in the forum. Pardon if anything is not right.
Additional context
Add any other context or screenshots about the feature request here.
question feature request