Laravel provides a predefined folder structure that helps developers organize routes, controllers, models, views, configuration, database files, and other application resources.
In this lesson, you will explore the important directories and files created when you install a Laravel application.
After creating a Laravel project named
student-app, you will find a structure
similar to the following. Some files and directories
may differ between Laravel versions.
student-app/
|
|-- app/
|-- bootstrap/
|-- config/
|-- database/
|-- public/
|-- resources/
|-- routes/
|-- storage/
|-- tests/
|-- vendor/
|
|-- .env
|-- .env.example
|-- artisan
|-- composer.json
|-- composer.lock
|-- package.json
|-- phpunit.xml
Each directory has a particular responsibility. Understanding these locations helps you find the correct file when building an application.
Example:
routes/ directory.app/Http/Controllers/.resources/views/.database/migrations/.
The app/ directory contains much of your
application's PHP code, including controllers, models,
middleware, and other application classes.
app/
|
|-- Http/
| |-- Controllers/
| |-- Middleware/
|
|-- Models/
Important locations:
app/Http/Controllers/ — HTTP controllers
that handle requests and coordinate application logic.
app/Models/ — Eloquent models that
represent and work with application data.
app/Http/Middleware/ — application
middleware classes when created or provided by
the installed Laravel structure.
For example, a student management application might
have a StudentController.php controller
and a Student.php model.
Example file paths:
app/Http/Controllers/StudentController.php
app/Models/Student.php
The routes/ directory contains route
definitions that connect incoming requests to
application behavior.
Common route files:
web.php — web routes, commonly using session and cookie features.console.php — console-related routes and definitions.api.php — API routes when the API routing file is installed or configured.
The available route files depend on your Laravel
version and project setup. For example, some newer
Laravel applications do not include
routes/api.php until API routing is installed.
Example: routes/web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/students', function () {
return 'Student List';
});
When a user opens the /students URL using
a GET request, Laravel returns the text
Student List.
The resources/ directory contains view
templates and frontend resources.
resources/
|
|-- views/
| |-- welcome.blade.php
|
|-- css/
|-- js/
Important locations:
resources/views/ — Blade templates.resources/css/ — frontend CSS source files in setups that use them.resources/js/ — JavaScript source files in setups that use them.Example view:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Student Page</title>
</head>
<body>
<h1>Welcome to Student Management</h1>
</body>
</html>
Save the example as
resources/views/students.blade.php.
You can return it from a route with
return view('students');.
The database/ directory contains files
used to create, populate, and test your database.
database/
|
|-- migrations/
|-- seeders/
|-- factories/
What each directory does:
Example migration command:
php artisan make:migration create_students_table
Laravel creates a migration file in
database/migrations/.
You will learn migrations, seeders, and factories in later lessons.
The public/ directory is the web entry
point for a standard Laravel application. The web
server should serve requests from this directory
rather than exposing the entire project directory.
public/
|
|-- index.php
|-- robots.txt
|-- favicon.ico
The exact files vary by project. The key file is
index.php, which serves as the entry
point for HTTP requests.
Important security rule:
Do not configure your production web server to expose
the project root. Doing so could reveal sensitive
files such as .env, source code, and
configuration files.
Uploaded user files should also be handled carefully. Laravel's storage system provides mechanisms for managing public and private files.
The config Directory
The config/ directory contains configuration
files for different application services.
config/
|
|-- app.php
|-- database.php
|-- cache.php
|-- mail.php
|-- session.php
The exact files depend on the Laravel version.
For example, config/database.php
contains database connection settings.
The bootstrap Directory
The bootstrap/ directory contains files
that initialize the Laravel application.
bootstrap/
|
|-- app.php
|-- cache/
The precise structure varies across Laravel versions. Avoid modifying bootstrap files unless you understand the configuration or customization you need.
The project root contains several files that control dependencies, environment settings, and command-line operations.
| File | Purpose |
|---|---|
.env |
Environment-specific settings and secrets. |
.env.example |
Example environment configuration. |
artisan |
Laravel command-line entry point. |
composer.json |
PHP dependencies, package constraints, and Composer configuration. |
composer.lock |
Exact resolved package versions for reproducible dependency installation. |
package.json |
Frontend package scripts and JavaScript dependencies when used. |
Keep real credentials and application secrets out
of public repositories. In particular, do not publish
the real .env file.
Complete these tasks to practise navigating a Laravel application.
app/ directory.routes/web.php.resources/views/ directory.database/migrations/ directory.public/index.php entry point.composer.json and artisan.Challenge:
Create a new view named
student-details.blade.php in
resources/views/ and display a heading
that says "Student Details".
In the next lesson, you will learn how to use Laravel Artisan commands to create controllers, models, migrations, and other application components.
1. Where are Laravel Blade views normally stored?
2. Which directory normally contains Laravel migrations?
3. Which file is Laravel's HTTP entry point in a standard project?