Laravel Directory structure for beginners
✅ Laravel Folder Structure
app/
๐This folder contains the main code of your application.
Http/ – Your controllers and middleware live here (handles user requests).
Models/ – These are used to talk to the database (like User.php).
Providers/ – These files help start services like routes, events, etc.
bootstrap/
๐Used to boot (start) your Laravel app.
- It also contains a cache folder to store compiled files for faster loading.
config/
๐All the settings of your app are here.
Examples:
app name
timezone
mail configuration
database info, etc.
database/
๐Contains everything related to your database.
migrations/ – Code for creating or changing tables.
seeders/ – Used to add sample data.
factories/ – Generate fake data for testing.
public/
๐This is the only folder visible to the user in the browser.
index.php is the file that starts Laravel.
You can also store images, CSS, and JavaScript here.
resources/
๐This folder has your HTML views and frontend files.
views/ – Contains Blade templates (Laravel’s HTML files).
css/ and js/ – For custom styles and scripts.
routes/
๐This is where you define URLs for your app.
web.php – For browser routes (like homepage, about page).
console.php – For Artisan CLI commands.
Example:
Route::get('/', function () {
return view('welcome');
});
storage/
๐Used to store files, like:
logs
uploaded files
cache files
Laravel uses this folder for internal data.
tests/
๐Write tests here to check if your app works properly.
vendor/
๐Contains all the Laravel files and libraries installed via Composer.
๐ Don't touch this folder manually.
๐ง Important Files
.env – Important settings like database, mail, app key, etc.
artisan – Command line tool to run Laravel commands.
composer.json – Keeps track of all PHP libraries.
vite.config.js – Settings for CSS/JS build tools.
package.json – Used for JavaScript packages (NPM).
✅ Summary Table
Folder/File | What it Does |
app/ | Main app logic (controllers, models) |
bootstrap/ | Starts Laravel app |
config/ | App settings |
database/ | Migrations and sample data |
public/ | Browser-visible files |
resources/ | Views and frontend code |
routes/ | Defines URLs |
storage/ | Stores logs, files, cache |
tests/ | App testing code |
vendor/ | Laravel framework and packages |
.env | Environment settings |
artisan | Laravel command line tool |
Explanation in Hinglish
✅ Main Laravel Project Structure
your-project/
│
├── app/
├── bootstrap/
├── config/
├── database/
├── public/
├── resources/
├── routes/
├── storage/
├── tests/
├── vendor/
│
├── .env
├── artisan
├── composer.json
├── vite.config.js
└── ...
app/
– Your core application code
๐ Yeh folder Laravel ka core hota hai, jisme controller, models, and logic rehta hai.
Http/ – Controllers, Middleware, and requests yahan hote hain.
Models/ – Aapke database models (e.g., User.php) yahan bante hain.
Providers/ – Laravel ki services register karne ke liye.
bootstrap/
๐ Laravel ko boot (start) karne ke liye yeh folder use hota hai.
app.php – Framework start karne ka file.
cache/ – Laravel ka optimization aur caching data.
config/
๐ Saare configuration files yahan hote hain (like mail, database, app name, etc.)
Example: app.php
, database.php
, mail.php
, etc.
database/
๐ Database se related saari cheezein:
migrations/ – Table create/edit ka code.
seeders/ – Sample data insert karne ke liye.
factories/ – Fake data generate karne ke liye (testing).
public/
๐ Yeh folder web-accessible hota hai. Jab user aapka site kholta hai, yeh folder serve hota hai.
index.php – Laravel ka entry point.
css/, js/ – Static assets like images, JS, CSS.
resources/
๐ Views aur frontend assets ke liye.
views/ – Blade templates (like HTML) yahan likhte hain.
css/ & js/ – Frontend code likhne ke liye.
routes/
๐ Saare URL routes yahan define hote hain.
web.php – Browser ke routes (GET, POST).
console.php – Artisan CLI ke liye.
api.php (not shown here but usually present) – API ke routes ke liye.
๐ง Example route in web.php
:
Route::get('/', function () {
return view('welcome');
});
storage/
๐ Logs, user uploads, and framework data ke liye.
logs/ – Errors and logs.
app/ – Uploaded files.
framework/ – Cache, sessions, views storage.
tests/
๐ Application ke test cases likhne ke liye (PHPUnit ya Pest use karke).
vendor/
๐ All packages and Laravel framework files jo Composer install karta hai.
❌ Never touch this manually.
๐ง Important Root Files:
.env
– Project ke environment/config (DB, mail, etc.)artisan
– Laravel CLI tool. Use it to run commands:php artisan serve php artisan migrate
composer.json
– Installed PHP packages ka record.vite.config.js
– Frontend build configuration (Vite for assets).package.json
– NPM packages list (for JS & CSS).
๐ Summary in Hinglish
Folder/File | Kaam (Use) |
app/ | Controllers, Models, Logic |
bootstrap/ | Laravel ko start karne ka system |
config/ | App ke settings/configs |
database/ | Tables banane ka code + test data |
public/ | Browser se visible files (index.php) |
resources/ | Views (HTML) + frontend code |
routes/ | URLs define karne ke liye |
storage/ | Logs, uploads, cache |
tests/ | App testing |
vendor/ | All Laravel + 3rd party libraries |
✅ Main Folders You Should Work On First
routes/web.php
1. ๐ ๐น Why?
This is where you define your website's URLs and actions.
๐ธ Example:
phpCopyEditRoute::get('/', function () {
return view('welcome');
});
➡️ Start here to create routes like /about
, /contact
, etc.
resources/views/
2. ๐ ๐น Why?
This folder contains your Blade templates – basically the HTML pages of your app.
๐ธ Example:
Create a file like about.blade.php
to design your "About Us" page.
app/Http/Controllers/
3. ๐ ๐น Why?
This is where you write your logic for routes using Controllers.
๐ธ Example:
If you want to handle form submissions, database access, etc.
➡️ Use php artisan make:controller PageController
to create a controller.
app/Models/
4. ๐ ๐น Why?
If you're using a database, Models help you interact with tables.
๐ธ Example:
phpCopyEdit$user = User::all(); // Gets all users
➡️ Use php artisan make:model Post
to create a model.
resources/css/
and resources/js/
(optional at first)
5. ๐ ๐น If you’re adding custom styles or JS, you can update these.
Comments
Post a Comment