Class 'App\models\Test' not found when try to access model
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Title: Solving "Class 'App\models\Test' not found" Error in Laravel Applications
Introduction: Laravel is a versatile PHP framework that makes building web applications simple and efficient. In this blog post, we will delve into the issue of 'Class 'App\models\Test' not found', a common error message encountered when trying to access models within your Laravel project. We will examine the different reasons behind this error and provide possible solutions to overcome it.
Why does this Error Occur?
The error "Class 'App\models\Test' not found" is generally faced in Laravel applications when working with models, specifically when using namespaces or autoloading. The primary reason for this problem could be due to incorrect file path and/or model name within your project structure, a missing namespace declaration, or issues with the composer configuration.
Solving the Issue:
To start fixing the issue, you need to ensure that your model file is located correctly in the folder 'app/models', as mentioned in the example code snippet provided. Additionally, it's crucial to verify if the class name defined within the model file and namespace match that of the Test model.
Here are some steps you could follow:
1. Check the file path and namespaces
Ensure that your Test model is located at 'app/models', with a correspondingly named PHP file containing the class definition. The namespace should be declared as expected, such as 'App\Http\Controllers'. If it's different, make sure to update both the folder structure and model file accordingly.
2. Composer autoloading
Composer is an essential tool for handling dependencies in Laravel applications. Since the framework expects your codebase to follow standard PHP coding practices, ensuring that your composer.json file is up-to-date can help resolve this issue:
- Verify if you have defined your namespace in the 'autoload' section of your composer.json file:
"autoload": {
"classmap": [
"app/models",
...
]
}
- Run 'composer dump-autoload' to update and refresh the autoloader. This command will scan all defined namespaces in your composer.json file and generate a classmap for them, allowing Laravel to find your model correctly.
3. Test the changes
After making these necessary updates, test your application to ensure that the error message no longer appears. If you are still encountering issues, check the error log or consult Laravel documentation for additional guidance.
Conclusion:
The "Class 'App\models\Test' not found" issue is commonly faced while using Laravel framework when interacting with your models in a controller or another class. By following best practices and ensuring that your file path, namespace declarations, and composer configuration are correct, you should be able to resolve this error. If the problem persists, consider seeking support from the Laravel community for further assistance.