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

Second Edit:

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 theUser andTeam models, therefore a namespace change alone will not work.

You shouldn't edit any files inside thevendor/laravel/spark-aurelius (aurelius codename will vary depending on your version) as these changes are not tracked.

With Spark, you should add the following lines into yourapp/Providers/SparkServiceProvider.php:

public function register()

You can set your own customApp\Models directory, rather than using the above example.

Finally you will need to update any references you make to your models, e.g. update controllers fromuse App\User touse App\Models\User.

Source: Laravel Spark 6.0 Customization

5th Jan 2020 Update: Remember to also updateSTRIPE_MODEL andBRAINTREE_MODEL values in your .env to your new namespace.

Laravel Spark 9.0 removes Braintree support, therefore you only need to updateCASHIER_MODEL in 9.0.

21st Dec 2020 Update: Laravel 8.x now keeps all models in theapp\Models directory 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 inapp\Models.




You need to changeUser model namespace:

namespace App\Models;



Try renaming the namespace. :)

namespace App\Models;



change namespace, and use like this

namespace App\Models;

People are also looking for solutions to the problem: php - How to use ng-app and ng-controller for many pages?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.