简体   繁体   中英

ReflectionException Class does not exist psr-4

I'm fairly new to laravel and have encountered a problem with the psr-4 autoloading in my application.

My folder structure:

-app
 -config
  -controllers
   -UsersController
  -Mynamespace
   -User.php

My composer.json file:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "psr-4": {
      "Mynamespace\\": "app/Mynamespace"
    }

Then I ran:

composer dump-autoload

My User model:

<?php namespace Mynamespace;

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Eloquent;

class User extends Eloquent implements UserInterface, RemindableInterface {
...

My vendor/composer/autoload-psr4.php:

...
return array(
    'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
    'Mynamespace\\' => array($baseDir . '/app/Mynamespace'),
);

Changed my config/auth.php to:

'model' => 'Mynamespace\User',

I keep getting a ReflectionException Class User does not exist error. Please help!

You reflection exception

Class User does not exist error

is complaining about not being able to find a class named User . I don't see a class named User defined anywhere in the above code. I see a class named Mynamespace\\User , but I don't see a global class named user.

Knowing the context that you're seeing this exception in would help, but my guess is something told Laravel to instantiate a global User object (dependency injected type hints? Instantiating an object through app()->make ? Directly Instantiating an object?). Without that context it's not likely anyone will be able to track this down for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM