MDN's avatar
Level 1

Artisan Tinker returning 'not found in eval()'d code

I'm trying to run $user = new App\User; like in the Eloquent 101 vide, but everytime I do that, I keep getting an error from tinker saying 'PHP Fatal error: Class 'App\User' not found in eval()'d code on line 1'

Does anyone know what is causing this?

0 likes
6 replies
pmall's avatar

Is your namespace / file directory / file name / class name correct on the user model ?

drimbo's avatar

In my case I forgot to add 'extends Model' upon the manual creation of the Model Class. I think it is always better to use: php artisan make:model Modelname -m on the command line which creates the Model the correct way and the migration in the same line

vlass's avatar

i had the same problem but SOLVED! u just have to check the problem i define class categories like class coments extends model so to problem was there i suggest u use tinker help to find the problem easly

jplew's avatar

I had the same problem, until I remembered that I moved all my models into a sub-directory:

App\Models\User::all()

rather than:

App\User::all()

Please or to participate in this conversation.