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

Reached replied 3 years ago

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

VolvoOlympian replied 3 years ago

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?

Reached replied 3 years ago

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 :)

VolvoOlympian replied 3 years ago

Pastebin would be great, thank you

Reached replied 3 years ago

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

Reached replied 3 years ago

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.

VolvoOlympian replied 3 years ago

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...

Reached replied 3 years ago

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?

VolvoOlympian replied 3 years ago

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...

jonlambert replied 3 years ago

How are you creating your project?

VolvoOlympian replied 3 years ago

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

pogachar replied 3 years ago

Try putting a backslash "" before Eloquent

class User extends \Eloquent implements UserInterface, RemindableInterface {

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

VolvoOlympian replied 3 years ago

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

KrqcS replied 3 years ago

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

danielsum replied 3 years ago

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 ?

KrqcS replied 3 years ago

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

danielsum replied 3 years ago

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...

rajanhossain replied 1 year ago

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

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us