Issues (47)

src/ForgetCachedPermissions.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Insenseanalytics\LaravelNovaPermission;
4
5
use Laravel\Nova\Nova;
0 ignored issues
show
The type Laravel\Nova\Nova was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Spatie\Permission\PermissionRegistrar;
7
8
class ForgetCachedPermissions
9
{
10
	/**
11
	 * Handle the incoming request.
12
	 *
13
	 * @param \Illuminate\Http\Request $request
14
	 * @param \Closure                 $next
15
	 *
16
	 * @return \Illuminate\Http\Response
17
	 */
18
	public function handle($request, $next)
19
	{
20
		$response = $next($request);
21
22
		if ($request->is('nova-api/*/detach') ||
23
			$request->is('nova-api/*/*/attach/*')) {
24
			$permissionKey = (Nova::resourceForModel(app(PermissionRegistrar::class)->getPermissionClass()))::uriKey();
0 ignored issues
show
The function app was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
			$permissionKey = (Nova::resourceForModel(/** @scrutinizer ignore-call */ app(PermissionRegistrar::class)->getPermissionClass()))::uriKey();
Loading history...
25
26
			if ($request->viaRelationship === $permissionKey) {
27
				app(PermissionRegistrar::class)->forgetCachedPermissions();
28
			}
29
		}
30
31
		return $response;
32
	}
33
}
34