Laravel Series · Chapter 1 · Introduction & Setup

Laravel क्या है?
Introduction & Installation in Hindi

Laravel — PHP का सबसे popular web framework। MVC pattern, Artisan CLI, Eloquent ORM, Blade templating — सब एक साथ। Installation से project structure तक — सब हिंदी में।

🏗️ MVC Pattern ⚙️ Installation 📁 Project Structure 🛠️ Artisan CLI ⚡ First App
v11Laravel Current Version
PHP 8.2+Minimum requirement
ArtisanBuilt-in CLI tool
MVCModel View Controller

📋 इस Article में क्या-क्या है

  1. Laravel क्या है? — क्यों use करें?
  2. Laravel vs Other Frameworks
  3. MVC Pattern — समझो
  4. Requirements — क्या चाहिए?
  5. Installation — Step by Step
  6. Project Structure — हर folder का मतलब
  7. Artisan CLI — Commands
  8. Environment Config — .env file
  9. First Route & Response
  10. Development Server — Run करना
1
Laravel क्या है? — क्यों Use करें?

Laravel — Taylor Otwell द्वारा बनाया गया free, open-source PHP web framework। 2011 में launch हुआ। आज PHP का #1 framework। "The PHP Framework for Web Artisans" — elegant syntax, powerful features।

Laravel = PHP + Best Practices + Powerful Tools। जो काम PHP में 100 lines में होता है वो Laravel में 10 lines में।

Routing — Clean URLs, HTTP methods, middleware।

Eloquent ORM — Database के साथ PHP objects में काम।

Blade Templating — Clean, powerful HTML templates।

Authentication — Login/Register ready-made।

Artisan CLI — Code generate करना one command में।

Queue, Events, Mail — Complex features simple API से।

Security — CSRF, XSS, SQL Injection built-in protection।


2
Laravel vs Other Frameworks
Laravel
Full-featured, Elegant
Symfony
Enterprise, Complex
CodeIgniter
Lightweight, Simple
FeatureLaravelSymfonyCodeIgniter
Learning CurveMediumHardEasy
ORM✅ Eloquent✅ Doctrine❌ Basic
CLI Tool✅ Artisan✅ ConsoleLimited
Authentication✅ Built-inPartial❌ Manual
Queue System✅ Built-in✅ Partial
Real-time✅ EchoPartial
Community⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐
Jobs🔥 Most demandEnterpriseDeclining
✅ Laravel क्यों? सबसे ज़्यादा jobs, best documentation, largest community, most features built-in। Beginners के लिए सबसे अच्छा choice।

3
MVC Pattern — Model View Controller

MVC — Application को 3 parts में divide करता है। Code organized रहता है, team work आसान, testing simple। Laravel पूरी तरह MVC follow करता है।

M
Model
Database Logic
C
Controller
Business Logic
V
View
HTML Display
ComponentमतलबLaravel मेंLocation
ModelData & Database rulesEloquent Model classesapp/Models/
ViewHTML display layerBlade templatesresources/views/
ControllerRequest handle, logicController classesapp/Http/Controllers/
RouteURL → Controller mapRoute definitionsroutes/web.php
MVC FLOW — User Request कैसे Handle होती है
// 1. User browser में URL type करता है
// GET /products

// 2. routes/web.php — Route match होती है
Route::get("/products", [ProductController::class, "index"]);

// 3. app/Http/Controllers/ProductController.php
public function index() {
  $products = Product::all(); // Model — DB से data
  return view("products.index", compact("products")); // View
}

// 4. resources/views/products/index.blade.php
// @foreach($products as $product) ... @endforeach

// 5. User को HTML response मिलती है

4
Requirements — क्या चाहिए?
RequirementMinimum VersionRecommended
PHPPHP 8.2PHP 8.3+
Composer2.xLatest
MySQL/MariaDBMySQL 8.0MySQL 8.0+
Node.jsv18+v20+ LTS
NPMv10+Latest
💡 Easy Setup: Herd (Mac) या Laravel Herd for Windows use करो — PHP, Nginx, MySQL सब एक click में install। Alternatively XAMPP या Laragon use करो।

5
Installation — Step by Step
STEP 1 — Composer Install करो (अगर नहीं है)
# Check composer installed है?
composer --version

# Download from https://getcomposer.org/
# Mac/Linux:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

# Verify
composer --version # Composer 2.x.x
STEP 2 — New Laravel Project बनाओ
# Method 1 — Laravel Installer (recommended)
composer global require laravel/installer
laravel new myapp

# Method 2 — Composer create-project
composer create-project laravel/laravel myapp

# Latest version specify
composer create-project laravel/laravel myapp "^11.0"

# laravel new के बाद options आते हैं:
# ┌ Would you like to install a starter kit?
# │ ● No starter kit
# │ ○ Laravel Breeze
# │ ○ Laravel Jetstream
# └ (Select with arrows, Enter to confirm)
STEP 3 — Project Setup
# Project folder में जाओ
cd myapp

# .env file configure करो
cp .env.example .env

# Application key generate करो
php artisan key:generate

# Storage link बनाओ (file uploads के लिए)
php artisan storage:link

# Development server start करो
php artisan serve
# → http://127.0.0.1:8000

6
Project Structure — हर Folder का मतलब
myapp/
├── app/ ← Application core code
│ ├── Console/ ← Artisan custom commands
│ ├── Exceptions/ ← Custom exception handlers
│ ├── Http/
│ │ ├── Controllers/ ← ✅ Controllers यहाँ
│ │ ├── Middleware/ ← Request filters
│ │ └── Requests/ ← Form validation classes
│ ├── Models/ ← ✅ Eloquent models यहाँ
│ └── Providers/ ← Service providers
├── bootstrap/ ← App bootstrapping
├── config/ ← ✅ Configuration files
│ ├── app.php ← App name, timezone, locale
│ ├── database.php ← DB connections
│ └── mail.php ← Mail config
├── database/ ← ✅ Migrations, Seeders, Factories
│ ├── migrations/ ← DB schema changes
│ ├── seeders/ ← Dummy data
│ └── factories/ ← Model factories
├── public/ ← ✅ Web root — index.php यहाँ
├── resources/
│ ├── views/ ← ✅ Blade templates (.blade.php)
│ ├── css/ ← Stylesheets
│ └── js/ ← JavaScript files
├── routes/ ← ✅ Route definitions
│ ├── web.php ← Web routes (browser)
│ ├── api.php ← API routes (/api/...)
│ └── console.php ← Artisan routes
├── storage/ ← Logs, cache, uploaded files
├── tests/ ← Unit & Feature tests
├── vendor/ ← Composer packages (git ignore)
├── .env ← ✅ Environment variables
├── composer.json ← PHP dependencies
├── package.json ← JS dependencies
└── artisan ← ✅ CLI tool entry point
💡 सबसे ज़रूरी folders याद रखो: app/Models (Models), app/Http/Controllers (Controllers), resources/views (Views), routes/web.php (Routes), database/migrations (DB Schema), .env (Config)।

7
Artisan CLI — Laravel का Swiss Army Knife

Artisan — Laravel का built-in command-line tool। Models, Controllers, Migrations, Seeders — सब एक command में generate। Development speed 10x।

ARTISAN — MOST USED COMMANDS
# Help — सब commands देखो
php artisan list
php artisan help make:model

# Development Server
php artisan serve # http://127.0.0.1:8000
php artisan serve --port=8080 # Custom port

# Code Generation
php artisan make:model Product # Model
php artisan make:model Product -m # Model + Migration
php artisan make:model Product -mcr # Model + Migration + Controller + Resource
php artisan make:controller ProductController
php artisan make:controller ProductController --resource # CRUD methods
php artisan make:migration create_products_table
php artisan make:seeder ProductSeeder
php artisan make:factory ProductFactory
php artisan make:request StoreProductRequest # Form Request
php artisan make:middleware CheckAdmin
php artisan make:mail WelcomeMail
php artisan make:job SendEmailJob
php artisan make:event UserRegistered

# Database
php artisan migrate # Run migrations
php artisan migrate:fresh # Drop + re-migrate
php artisan migrate:fresh --seed # Fresh + seed data
php artisan db:seed # Run seeders

# Cache
php artisan config:clear # Config cache clear
php artisan cache:clear # App cache clear
php artisan route:clear # Route cache clear
php artisan view:clear # View cache clear
php artisan optimize:clear # All clear

# Tinker — Interactive PHP REPL
php artisan tinker
# >>> User::all();
# >>> User::factory()->create();

8
.env File — Environment Configuration
.env — IMPORTANT SETTINGS
# Application
APP_NAME=MyApp
APP_ENV=local # local | staging | production
APP_KEY=base64:... # php artisan key:generate से
APP_DEBUG=true # Production में false करो
APP_URL=http://localhost

# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp
DB_USERNAME=root
DB_PASSWORD=

# Cache & Sessions
CACHE_DRIVER=file # file | redis | memcached
SESSION_DRIVER=file # file | database | redis
QUEUE_CONNECTION=sync # sync | database | redis

# Mail
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your@email.com
MAIL_PASSWORD=yourpassword
MAIL_FROM_ADDRESS=your@email.com
MAIL_FROM_NAME="${APP_NAME}"
.env VALUES — PHP में Access करना
<?php
// env() helper से
env("APP_NAME"); // "MyApp"
env("DB_HOST", "localhost"); // Default value

// config() helper से (better way)
config("app.name"); // "MyApp"
config("database.default"); // "mysql"
?>
⚠️ .env git में commit मत करो! .gitignore में already है। Passwords, API keys, DB credentials — सब .env में रखो, code में hardcode मत करो। Production पर server environment variables use करो।

9
First Route & Response — Hello Laravel!
routes/web.php — FIRST ROUTES
<?php

// routes/web.php
use Illuminate\Support\Facades\Route;

// Simple text response
Route::get("/", function () {
  return "🚀 Welcome to Laravel!";
});

// JSON response
Route::get("/api-test", function () {
  return response()->json([
    "success" => true,
    "message" => "Laravel working!",
    "version" => app()->version(),
  ]);
});

// View return करना
Route::get("/home", function () {
  return view("welcome"); // resources/views/welcome.blade.php
});

// Route with variable
Route::get("/hello/{naam}", function (string $naam) {
  return "नमस्ते, $naam!";
});
// Visit: /hello/Rahul → "नमस्ते, Rahul!"
?>

10
Development Server — Run & Test
SERVER START करो
# Basic server — http://127.0.0.1:8000
php artisan serve

# Custom host और port
php artisan serve --host=0.0.0.0 --port=8080

# Frontend assets (Vite) — npm run dev
npm install
npm run dev

# दोनों साथ चलाना (2 terminals)
# Terminal 1:
php artisan serve
# Terminal 2:
npm run dev

# Routes list देखना
php artisan route:list
php artisan route:list --path=api # API routes only
First App Checklist: composer install → .env setup → php artisan key:generate → DB create → php artisan migrate → php artisan serve → Browser खोलो!

Quick Reference — Important Artisan Commands
Commandकाम
php artisan serveDev server start
php artisan key:generateApp key set करो
php artisan make:model X -mcrModel+Migration+Controller+Resource
php artisan migrateDB migrations run
php artisan migrate:fresh --seedFresh DB + seed data
php artisan route:listAll routes show
php artisan tinkerInteractive PHP shell
php artisan optimize:clearAll caches clear
php artisan config:cacheConfig cache (production)

निष्कर्ष

Laravel PHP का best framework है। MVC pattern, powerful tools, large community — सब मिलकर development fast और enjoyable बनाते हैं। Installation हो गई — अब सीखते हैं।

Laravel = PHP + Best Tools। Manual PHP से 10x faster development।

MVC — Model (Data), View (HTML), Controller (Logic)। Separation of concerns।

Artisan — Code generate करो, server चलाओ, DB migrate करो।

.env — Credentials यहाँ। Code में कभी नहीं। Git में commit नहीं।

routes/web.php — सब URLs यहाँ define होते हैं।

🚀 अगला Chapter: Chapter 2: Laravel Routing — Route parameters, named routes, route groups, middleware, resource routes। URL structure complete।