1

I though I was clever to organise all the DB models into the folder as per Laravel 8 which I am running on my project...

What I did is :

  1. create the folder and move all the models into so now i.e. Articles.php is inside the app/Models folder
  2. add "namespace App\models;" in each model file
  3. replace all the instance of "use App\Article;" by "use App\Models\Article;" in all controllers

Now I get an error "Class '\App\User' not found (View: ...list.blade.php) which is displayed through the controller where all the models are properly defined as above.

If I run artisan dumpautoload I get "Class App\models\Article located in ./app/Models/Article.php does not comply with psr-4 autoloading standard. Skipping."

So what do I have to do to fix that issue?

6
  • @ZiaYamin There is no use of model files there. Commented Mar 2, 2021 at 11:01
  • 3
    namespace App\models to namespace App\Models m to M Commented Mar 2, 2021 at 11:03
  • The folder is Models and all the namspaces App\Models I checked that @KamleshPaul but I see that the dumpautoload error is "Class App\models\Article located in ./app/Models/Article.php" where does "models" with lowercase come from? Should I rename everything with lowercase? Commented Mar 2, 2021 at 11:06
  • I am so sorry only the Article model had a namespace with lowercase... thank you @KamleshPaul Commented Mar 2, 2021 at 11:11
  • 1
    Indeed there was still one issue... and that post fixed it. Thank you a million @KamleshPaul Commented Mar 2, 2021 at 11:15

1 Answer 1

2

Make sure the namespace you use is capitalized correctly - namespace App/Models rather than the App/models you noted above.

You may also need to update the file config/auth.php. Find the 'User Providers' section and look for the 'model' entry which points to the User model.

Sign up to request clarification or add additional context in comments.

2 Comments

But there is still an error "vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php:183" ... "Class '\App\User' not found (View: /.../resources/views/dashboard/list.blade.php) and there is no use of User in that file.
What is the full error message?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.