php - Laravel 5 - Moved User model to App/Models causing autoload issues
Working on a inherited Laravel Spark project that contained two User models.
One is the standard Spark model inside the App directory but the other is inside App/Models. I have combined the two models and updated the auth.php to reference the User model inside the Models directory but composer dump-autoload is saying it cannot find the App/User model.
How can I tell the autoloader that the User model is not there any more but instead in the Models directory?
I have changed the namespace to App/Models but still receive the error:
class_parents(): Class App\User does not exist and could not be loaded
In my terminal when running dump-autload
Fixed, didn't realise the namespace was referenced so much. Did a find and replace on App\User and sorted the issue.
A standard Laravel installation will work by simply changing the namespace as others have mentioned; however Laravel Spark references the
Teammodels, therefore a namespace change alone will not work.
You shouldn't edit any files inside the
aureliuscodename will vary depending on your version) as these changes are not tracked.
With Spark, you should add the following lines into your
You can set your own custom
App\Modelsdirectory, rather than using the above example.
Finally you will need to update any references you make to your models, e.g. update controllers from
Source: Laravel Spark 6.0 Customization
5th Jan 2020 Update: Remember to also update
BRAINTREE_MODELvalues in your .env to your new namespace.
Laravel Spark 9.0 removes Braintree support, therefore you only need to update
21st Dec 2020 Update: Laravel 8.x now keeps all models in the
app\Modelsdirectory by default. Even if you're on an older version of Laravel (e.g. 6.x) but are using Laravel Spark 11, then you do not need to do any of the above. Laravel Spark 11 will assume your models live in
You need to change
Try renaming the namespace. :)
change namespace, and use like this