0

I'm new to Laravel. I just installed Laravel 5 and have been going through some video tutorials in order to learn how it works.

I want to use the User class as it seems like it is very useful. In my web.php (routes) file, I have:

use app\Models\User; Route::get('/users', function (){ $users = User::all(); //select * from users return $users; }); 

I get the following error upon loading that route in my browser:

enter image description here

I have a User.php file placed in my app/Models/ directory, and also changed in my auth.php file for it to reference this.

There are countless questions like this online and I try the fixes but I can't seem to get it to work. Any ideas?

Thanks!

1
  • is you app still called app or did you change it using php artisan app:name <name> ? Commented Feb 7, 2017 at 20:24

1 Answer 1

1

Remove Models from use statement. It's not directory... Model is in namespace App so use:

use App\User; 

Namespace and Directory is completely different things...

Or if you want to use in directory app/Models go to User.php model file and change namespace from App to App\Models

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

4 Comments

I had this originally, and it didn't work. Just changed it back now, and no dice.
Can you paste your User model content? and which is Line 10 on your route file?
I believe I just fixed it.
Yeah, because it's namespace is App and directory is app

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.