Reputation: 1521
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:
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!
Upvotes: 0
Views: 1084
Reputation: 2076
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
Upvotes: 1