Class 'Eloquent' not found

I am a beginner to laravel. I have just downloaded the latest version of laravel and deployed on my local machine. I first setup the config to the mysql database, then I made a file called User.php and put the following in it: class User extends Eloquent { protected $table = 'test_user'; protected $primaryKey = 'MID'; protected $timestamps = false; }

Then I saved it and try to run this page, but it says "Class 'Eloquent' not found" on that line? Could someone please point out what I have missed or what I have done incorrectly? Thanks

  • 2 years ago

There is already a model called User.php in your models directory, it contains the boilerplate you need.

Thanks, I actually tried that one before but it also shows "Class 'Eloquent' not found", that's why I was trying to follow the laravel documentation to create one from scratch... Why is that happening?

Can you please copy and paste your code in here from your model (use the code markup or a pastebin), that would make it easier :)

Pastebin would be great, thank you

I have never encountered a similar problem. And you did not modify your installation in any way besides setting up your database connection?

Please delete the file you created yourself, and just use the one that was supplied with the installation, it should work with no problem tbh.

Im talking about the User.php in Models.

I also added a folder with some static html files inside the "public" folder and that's all... yes this does sounds strange.

Yes I deleted the another file and uses the original User.php that comes with the installation, and the error is the same...I have tried clearing cache and things like that as well...

Could you maybe try doing a completely fresh installation? I'm also curious about your setup, are you using Homestead or some other Vagrant box?

Yes I am creating a new laravel project right now, will report back when it's done. Im just using XAMPP and composer.

EDIT: Oh no, a fresh project creation gives me the same error...

How are you creating your project?

composer create-project laravel/laravel --prefer-dist in command prompt

Try putting a backslash "\" before Eloquent

class User extends \Eloquent implements UserInterface, RemindableInterface {

Also do you still have it in app/models directory?

Thanks, yes the User.php is still in the app/models. But adding the backslash does not work for me unfortunately...

Hi larahub, did you solve your problem ? I've got the same issue ! Please let me know :)

Try maybe to check if : Illuminate\Database\Eloquent\Model exist in the vendors folder and check app/config/app.php if there is a eloquent aliases...

Eventually make a :

composer dump-autoload and php artisan dump-autoload ?

Hi and Thanks for your answer :

So first of all, i have this in my vendor :


And in app/config/app.php i have :

'Eloquent' => 'Illuminate\Database\Eloquent\Model',

Then, i just tried to do composer dump-autoload & artisan dump-autoload at the root of my project.

But i still have :

Fatal error: Class 'Eloquent' not found in C:\wamp\www\Alpha\app\models\User.php on line 8

Did you try to include a direct ref in your User model like :

use Illuminate\Database\Eloquent\Model as Eloquent;

Seems to be a problem of autoload maybe issue with DOCUMENT_ROOT path config of your Wamp install...

This worked very well in my case. Thanks a lot.