ReflectionException Class does not exist psr-4

890 views Asked by At

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!

1

There are 1 answers

0
Alana Storm On

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.