Laravel project structure organizes your code and files clearly. It helps you find and manage parts of your app easily.
Laravel project structure
laravel_project/ ├── app/ ├── bootstrap/ ├── config/ ├── database/ ├── public/ ├── resources/ ├── routes/ ├── storage/ ├── tests/ ├── vendor/ ├── artisan ├── composer.json ├── .env
app/ holds your main code like controllers and models.
public/ is the web root where index.php lives and assets are served.
app/ folder with main code parts: controllers handle requests, models work with data, and providers set up services.app/ ├── Http/ │ ├── Controllers/ │ └── Middleware/ ├── Models/ └── Providers/
routes/ folder contains files where you define URLs your app responds to, like web pages or API calls.routes/ ├── web.php ├── api.php └── console.php
resources/ holds templates for pages (views/), language files, and styles.resources/ ├── views/ ├── lang/ └── css/
This simple route in routes/web.php shows how Laravel uses the project structure. It listens for the home page URL and returns a welcome view from resources/views/welcome.blade.php.
<?php // File: routes/web.php use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); });
Keep your code inside app/ to follow Laravel's best practices.
Use public/ for files that browsers need to access directly, like images and scripts.
Configuration files in config/ let you change settings without touching code.
Laravel project structure organizes files into clear folders for code, views, routes, and configs.
This structure helps you build, maintain, and scale your app easily.
Understanding the folders lets you find and change parts of your app quickly.
Practice
Solution
Step 1: Understand the purpose of the
Theroutesfolderroutesfolder holds files that define how URLs map to code actions in Laravel.Step 2: Compare with other folders
Theappfolder contains core code,resourcesholds views and assets, andconfigstores configuration settings.Final Answer:
routes-> Option DQuick Check:
URL routes =routesfolder [OK]
routes folder [OK]- Confusing
appwith routes folder - Thinking views are in
routes - Mixing config files with routes
Solution
Step 1: Identify where Blade templates are stored
Blade templates are stored in theresources/viewsfolder by Laravel convention.Step 2: Verify other options
app/Viewsis not standard,public/templatesis for public assets, andconfig/viewsis not used for templates.Final Answer:
resources/views-> Option CQuick Check:
Blade templates =resources/views[OK]
resources/views folder [OK]- Putting templates in
appfolder - Confusing public assets with views
- Trying to store views in config folder
app/
Http/
Controllers/
resources/
views/
routes/
web.phpWhere should you place a new controller named
ProductController.php?Solution
Step 1: Locate where controllers go in Laravel
Controllers are placed insideapp/Http/Controllersfolder to handle requests.Step 2: Check other folders for controllers
resources/viewsis for templates,routesis for route files, andapproot is not for controllers.Final Answer:
app/Http/Controllers/ProductController.php-> Option AQuick Check:
Controllers =app/Http/Controllers[OK]
app/Http/Controllers [OK]- Placing controllers in views folder
- Putting controllers directly in app root
- Confusing routes folder with controllers
config('database.host') but get an error. What is the most likely cause?Solution
Step 1: Understand how config() works in Laravel
Theconfig()helper reads values from files in theconfigfolder, likedatabase.php.Step 2: Identify cause of error
Ifdatabase.phpis missing or misnamed,config('database.host')cannot find the value, causing an error.Final Answer:
Thedatabase.phpconfig file is missing or misnamed -> Option BQuick Check:
Missing config file = error onconfig()call [OK]
config() calls [OK]- Blaming routes or controllers for config errors
- Ignoring missing or misnamed config files
- Assuming views affect config values
Solution
Step 1: Identify where API routes are defined
API routes go inroutes/api.phpto separate them from web routes.Step 2: Locate correct controller and view folders
Controllers belong inapp/Http/Controllers, and views go inresources/views.Step 3: Check incorrect options
app/Modelsis for data models,publicis for assets,config/api.phpis not standard, and middleware folder is for request filters.Final Answer:
Updateroutes/api.php, create controller inapp/Http/Controllers, and add view inresources/views-> Option AQuick Check:
API route + controller + view folders = Updateroutes/api.php, create controller inapp/Http/Controllers, and add view inresources/views[OK]
routes/api.php, controllers in app/Http/Controllers [OK]- Putting API routes in
routes/web.php - Creating controllers in wrong folders
- Adding views outside
resources/views
Ready to prove it?
Pass the test and this pattern moves unknown
