orm icon indicating copy to clipboard operation
orm copied to clipboard

[BUG] Cannot instantiate abstract class

Open leamasuero opened this issue 5 years ago • 2 comments

laravel-doctrine/orm v1.4.10, Laravel Framework 5.5.45

Context: I have the following hierarchy:

abtstact User Admin extends User Professional extendes User

My config/auth.php:


    'providers' => [
        'users' => [
            'driver' => 'doctrine',
            'model' => \Models\User::class,
        ],
    ]
....

Expected behaviour

It should instantiate logged user. It could be a Professional or an Admin. Never a plain (abstract) User.

Actual behaviour

Most of the times, it works fine. However, I keep getting these errors in my logs. I believe that it happens where user session has expired and the auth service tries to load the user (it won't happen when a open a private window or after I sign into the app - just stale sessions).

[2019-04-20 21:09:51] production.ERROR: Cannot instantiate abstract class Models\User (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) {"exception":"[object] (ErrorException(code: 0):
Cannot instantiate abstract class \Models\\User (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) at /var/www/xyz.org.ar/vendor/laravel-doctrine/orm/src/Auth/DoctrineUserProvider.php:134, ErrorException(code: 0): 
Cannot instantiate abstract class \Models\\User (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) at /var/www/xyz.org.ar/vendor/laravel-doctrine/orm/src/Auth/DoctrineUserProvider.php:134, ErrorException(code: 0):
Cannot instantiate abstract class \Models\\User (View: /var/www/xyz.org.ar/resources/views/public/nav.blade.php) at /var/www/xyz.org.ar/vendor/laravel-doctrine/orm/src/Auth/DoctrineUserProvider.php:134, Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Cannot instantiate abstract class \Models\\User at /var/www/xyz.org.ar/vendor/laravel-doctrine/orm/src/Auth/DoctrineUserProvider.php:134)
[stacktrace]
#0 /var/www/xyz.org.ar/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(45): Illuminate\\View\\Engines\\CompilerEngine->handleViewException(Object(ErrorException), 1)

leamasuero avatar Apr 21 '19 00:04 leamasuero

The error says what does it mean, it cannot instantiate abstract class

vv12131415 avatar Apr 23 '19 15:04 vv12131415

I think is because of this: 'model' => \Models\User::class, and the fact that the User class is abstract.

It seems your users should not be able to log in.

geoffreyvanwyk avatar Apr 25 '19 15:04 geoffreyvanwyk