Reputation: 1590
I am attempting to move all my User code in to it's own package for potential use on multiple projects, everything is working fine except for when I try to login and I get the following error:
Class '\User' not found
Now, I am assuming that this is because for some reason it is not finding the User model (I am using the default one that comes with Laravel but just moved to
'Vendor/VendorName/PackageName/src/models'
I can see that I can reference the User model from app/config/auth.php but if I change this to my package namespace I am seeing the same error but with the different path, also, I don't think that this is the best way to do this as for every project I will need to set the app/config/auth.php model which could prove to be pain, especially as I forget things!
Upvotes: 2
Views: 2307
Reputation: 1962
My guess is that you have not autoloaded User. Below is an example of how Laravel do use autoload in composer, the User class is at installation placed inside "app/models", which is autoloaded there. If you have moved your User anywhere else you need to autoload it from there.
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models", // original path for User.php
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"your/new/path" // here you add your new path that should autoload
]
}
And do not forget to run composer dump-autoload
after updating your composer.json file!
Upvotes: 1