vscode-laravel-extra-intellisense icon indicating copy to clipboard operation
vscode-laravel-extra-intellisense copied to clipboard

PHP Fatal error: Uncaught ReflectionException: Class App\Policies\ModelPolicy does not exist in Command line code:1

Open Ruko97 opened this issue 1 year ago • 2 comments

System: Windows 11 Description: I installed the Laravel Extra Intellisense from the VS Code Extension marketplace. The extension never worked, and the following error message started to occur instead of running properly

PHP Fatal error: Uncaught ReflectionException: Class App\Policies\ModelPolicy does not exist in Command line code:1 Stack trace: #0 Command line code(1): ReflectionClass->__construct('App\Policies\Mo...') #1 [internal function]: {closure}('App\Policies\Mo...', 'App\Model') #2 Command line code(1): array_map(Object(Closure), Array, Array) #3 {main} thrown in Command line code on line 1

Because of backward compatibility, I am using PHP 7.4 and Laravel Framework 5.8. Could that be the reason the extension doesn't work?

Ruko97 avatar Oct 16 '24 15:10 Ruko97

For other projects I have tested this extension with all seems to be working normal. In one though I get the same error as @Ruko97. I'm not sure why, but inside the file app/Providers/AuthServiceProvider.php there was this:

    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        'App\Model' => 'App\Policies\ModelPolicy',
    ];

I removed the entry and left the $policies array empty and the error stopped popping up! I don't know if I have inadvertently broken something - I hope not! Does anyone know what that entry could be doing there?

papandrk avatar Oct 27 '24 23:10 papandrk

@papandrk I'm pretty sure it's a placeholder that was included with the default Laravel installation at some point - if you look for a class called App\Policies\ModelPolicy, you likely won't find it.

For that reason, I wouldn't consider this a bug with this package - it's doing its job!

patrick-cullen avatar Dec 17 '24 19:12 patrick-cullen