(1/1) FatalErrorException Class 'App\User' not found in HomeController.php (line 28)

455 views Asked by At

I'm actually making a laravel CRUD app.

So there is this model called User which has been created, but when I try to use it in a controller (In this case, HomeController.php), it says:

Here is line 28 from the controller:

I'm sorry if this question already exists but I've searched everywhere for a solution but could not find it.

Thank you.

2

There are 2 answers

1
Ian Welerson On BEST ANSWER

Ideally, you should post the line you are importing the model, and the first few lines of your model. But I will try to explore the possibilities of error.

Is your model inside a specific folder (just like app/MyModels/User.php) or just inside the default place when you use php artisan make:model? Remember to put the exact path in namespace line inside of model.

In the first line of your model you should have the path of your model with namespace. If the model is in its default directory, you should have the line below, but if it is inside of a folder, you have to put the folder path after de App:

namespace App;

Verify if you model is extends of Model:

class User extends Model {

In your controller the use line have the same path of namespace line in model, if you model is in default path, should be like this:

use App\User;

Remember that: the App is the namespace of your project, if you used the php artisan app:name command your namespace is no longer an App, and you should change it if you have the old name somewhere. If you using linux, remeber of the case sensitive.

If it does not work, put into the post the codes of the files I've listed so we can help.

2
Kyi Win Htin On

in the begining

<?php
use App\User;