0

I don't know what I have done with my Laravel 5.3 Project but I have this error in Laravel log:

local.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 {"exception":"[object] (Symfony\Component\Debug\Exception\FatalErrorException(code: 1): 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 at Command line code:1) [stacktrace] #0 {main} "}

my app.php

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Notifications\NotificationServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,

    /*
     * Package Service Providers...
     */
    Laravel\Passport\PassportServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

],

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => [

    'App' => Illuminate\Support\Facades\App::class,
    'Artisan' => Illuminate\Support\Facades\Artisan::class,
    'Auth' => Illuminate\Support\Facades\Auth::class,
    'Blade' => Illuminate\Support\Facades\Blade::class,
    'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
    'Bus' => Illuminate\Support\Facades\Bus::class,
    'Cache' => Illuminate\Support\Facades\Cache::class,
    'Config' => Illuminate\Support\Facades\Config::class,
    'Cookie' => Illuminate\Support\Facades\Cookie::class,
    'Crypt' => Illuminate\Support\Facades\Crypt::class,
    'DB' => Illuminate\Support\Facades\DB::class,
    'Eloquent' => Illuminate\Database\Eloquent\Model::class,
    'Event' => Illuminate\Support\Facades\Event::class,
    'File' => Illuminate\Support\Facades\File::class,
    'Gate' => Illuminate\Support\Facades\Gate::class,
    'Hash' => Illuminate\Support\Facades\Hash::class,
    'Lang' => Illuminate\Support\Facades\Lang::class,
    'Log' => Illuminate\Support\Facades\Log::class,
    'Mail' => Illuminate\Support\Facades\Mail::class,
    'Notification' => Illuminate\Support\Facades\Notification::class,
    'Password' => Illuminate\Support\Facades\Password::class,
    'Queue' => Illuminate\Support\Facades\Queue::class,
    'Redirect' => Illuminate\Support\Facades\Redirect::class,
    'Redis' => Illuminate\Support\Facades\Redis::class,
    'Request' => Illuminate\Support\Facades\Request::class,
    'Response' => Illuminate\Support\Facades\Response::class,
    'Route' => Illuminate\Support\Facades\Route::class,
    'Schema' => Illuminate\Support\Facades\Schema::class,
    'Session' => Illuminate\Support\Facades\Session::class,
    'Storage' => Illuminate\Support\Facades\Storage::class,
    'URL' => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View' => Illuminate\Support\Facades\View::class,

],

OS : Windows 10 Localhost : Laragon PHP Version : 5.7

That's my package.json

{ "name": "laravel/laravel", "description": "The Laravel Framework.", "keywords": ["framework", "laravel"], "license": "MIT", "type": "project", "require": { "php": ">=7.1.3", "barryvdh/laravel-cors": "^0.11.2", "beyondcode/laravel-websockets": "1.3", "dacastro4/laravel-gmail": "^5.1", "doctrine/dbal": "^2.8", "fideloper/proxy": "~4.0", "guzzlehttp/guzzle": "^6.3", "html2text/html2text": "^4.3", "jenssegers/mongodb": "", "laravel/framework": "^5.7", "laravel/passport": "^7.0", "laravel/socialite": "4.4.1", "laravel/tinker": "~1.0", "lcobucci/jwt": "^3.4", "league/csv": "^9.1", "league/oauth2-client": "^2.7", "microsoft/microsoft-graph": "^1.110", "moloquent/moloquent": "", "mongodb/laravel-mongodb": "", "php-amqplib/php-amqplib": "", "phpseclib/phpseclib": "2", "pusher/pusher-php-server": "~3.0", "soundasleep/html2text": "^2.1", "symfony/process": "^4.3", "webklex/laravel-imap": "^4.1" }, "require-dev": { "barryvdh/laravel-ide-helper": "^2.7", "filp/whoops": "~2.0", "fzaninotto/faker": "~1.4", "mockery/mockery": "~1.0", "phpunit/phpunit": "~7.0", "symfony/thanks": "^1.0" }, "autoload": { "classmap": [ "database/seeds", "database/factories" ], "psr-4": { "App\": "app/" } }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } }, "extra": { "laravel": { "dont-discover": [ ] } }, "scripts": { "post-root-package-install": [ "@php -r "file_exists('.env') || copy('.env.example', '.env');"" ], "post-create-project-cmd": [ "@php artisan key:generate" ], "post-autoload-dump": [ "Illuminate\Foundation\ComposerScripts::postAutoloadDump", "@php artisan package:discover" ], "post-update-cmd": [ "Illuminate\Foundation\ComposerScripts::postUpdate", "php artisan ide-helper:generate", "php artisan ide-helper:meta" ] }, "config": { "preferred-install": "dist", "sort-packages": true, "optimize-autoloader": true } }

3
  • class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ 'App\Model' => 'App\Policies\ModelPolicy', ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { $this->registerPolicies(); Passport::routes(); Passport::tokensCan([ 'admin' => 'Admin user/read-only mode', ]); } } Commented Apr 8, 2024 at 15:40
  • 1
    Please edit your question and provide the relevant code as well as the context (e.g. what were you doing when this happened). Commented Apr 8, 2024 at 15:45
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Apr 17, 2024 at 21:29

1 Answer 1

0

It's because you're passing a string when registering policies rather than the actual class.

Here's an example from Laravel Docs

use App\Policies\PostPolicy;
use Illuminate\Support\Facades\Gate;
 
/**
 * Register any authentication / authorization services.
 */
public function boot(): void
{
    Gate::define('update-post', [PostPolicy::class, 'update']);
}

What you seem to be doing is just passing a string such as

'App\Policies\Policy'

That's what I seem to be getting anyway from the context provide in the comment you made.

Please provide more context in your questions if you want better answers. At the moment it's very hard for anyone to try and help you because you've made it difficult to do so.

Sign up to request clarification or add additional context in comments.

1 Comment

I haven't created any custom Policies. 'App\Model' => 'App\Policies\ModelPolicy', was already in AuthServiceProvider

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.