How do I call a model in Laravel 5?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company
# How Do I Call a Model in Laravel 5? Solving the Classic Namespace Confusion As a senior developer, I’ve seen countless developers stumble over seemingly simple tasks in frameworks like Laravel. The struggle you are experiencing—trying to access a Model from a Controller and getting a "Class not found" error—is one of the most common hurdles when starting with Eloquent and MVC architecture. It usually boils down to a misunderstanding of how PHP namespaces, file structure, and dependency injection work together in the Laravel environment. Let's break down exactly why this happens and walk through the correct, idiomatic way to interact with your data models in Laravel. We will fix that error and establish a solid foundation for using Eloquent effectively. ## Diagnosing the Error: Why is Laravel Confused? The fatal error you encountered, `Class 'App\Http\Controllers\diamonds' not found`, tells us exactly where the problem lies: the controller is trying to find a class named `diamonds` within its own namespace (`App\Http\Controllers`), instead of looking for your Eloquent Model. In Laravel, models are not controllers; they are data structures defined by Eloquent, and they reside in a specific location that dictates their namespace. When you write `$diamonds = diamonds::find(1);`, PHP is looking for a class named `diamonds` inside the controller's directory structure, which doesn't exist if your model is correctly placed. The core issue is not *how* you call the method, but *where* the class is defined and how you are referencing it within your scope. ## The Correct Structure: Models and Namespaces To resolve this, we need to adhere to Laravel’s standard convention for placing Eloquent Models. ### Step 1: Correct Model Placement In modern Laravel applications (including Laravel 5 conventions), all Eloquent Models should reside in the `app/Models` directory. This structure ensures that when you use the `App\Models` namespace, the framework knows exactly where to look for your data classes. **Correct File Structure:** ``` app/ ├── Http/ │ └── Controllers/ │ └── TestController.php <-- Your Controller lives here └── Models/ <-- Place all Models here └── Diamond.php <-- Your Model definition ``` ### Step 2: Defining the Eloquent Model (The Fix) Let's correct your model file. Instead of defining it directly in `app/`, we place it in `app/Models/`. We will also use a more conventional singular naming convention for models (e.g., `Diamond` instead of `diamonds`) and ensure proper class structure. **`app/Models/Diamond.php`:** ```php name if you have a 'name' column var_dump($diamond); } else { echo "Diamond not found!"; } } } ``` Notice the difference: we are referencing `Diamond` (the class name) and using the correct namespace (`App\Models`) to qualify it. This method is clean, readable, and robust—a key principle when building larger applications on Laravel, as discussed in best practices found on platforms like [laravelcompany.com](https://laravelcompany.com). ## Conclusion The mystery of how to call a model boils down to proper organization and namespace management. By adhering to the `app/Models` directory convention and using the correct `use` statements in your controllers, you ensure that PHP can correctly resolve the location of your Eloquent classes. This disciplined approach is fundamental to writing scalable and maintainable code in Laravel. Master these structural details, and building complex features becomes significantly easier!