Laravel क्या है?
Introduction & Installation in Hindi
Laravel — PHP का सबसे popular web framework। MVC pattern, Artisan CLI, Eloquent ORM, Blade templating — सब एक साथ। Installation से project structure तक — सब हिंदी में।
📋 इस Article में क्या-क्या है
- Laravel क्या है? — क्यों use करें?
- Laravel vs Other Frameworks
- MVC Pattern — समझो
- Requirements — क्या चाहिए?
- Installation — Step by Step
- Project Structure — हर folder का मतलब
- Artisan CLI — Commands
- Environment Config — .env file
- First Route & Response
- Development Server — Run करना
Laravel — Taylor Otwell द्वारा बनाया गया free, open-source PHP web framework। 2011 में launch हुआ। आज PHP का #1 framework। "The PHP Framework for Web Artisans" — elegant syntax, powerful features।
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।
| Feature | Laravel | Symfony | CodeIgniter |
|---|---|---|---|
| Learning Curve | Medium | Hard | Easy |
| ORM | ✅ Eloquent | ✅ Doctrine | ❌ Basic |
| CLI Tool | ✅ Artisan | ✅ Console | Limited |
| Authentication | ✅ Built-in | Partial | ❌ Manual |
| Queue System | ✅ Built-in | ✅ Partial | ❌ |
| Real-time | ✅ Echo | Partial | ❌ |
| Community | ⭐⭐⭐⭐⭐ | ⭐⭐⭐⭐ | ⭐⭐⭐ |
| Jobs | 🔥 Most demand | Enterprise | Declining |
MVC — Application को 3 parts में divide करता है। Code organized रहता है, team work आसान, testing simple। Laravel पूरी तरह MVC follow करता है।
Database Logic
Business Logic
HTML Display
| Component | मतलब | Laravel में | Location |
|---|---|---|---|
| Model | Data & Database rules | Eloquent Model classes | app/Models/ |
| View | HTML display layer | Blade templates | resources/views/ |
| Controller | Request handle, logic | Controller classes | app/Http/Controllers/ |
| Route | URL → Controller map | Route definitions | routes/web.php |
// 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 मिलती है
| Requirement | Minimum Version | Recommended |
|---|---|---|
| PHP | PHP 8.2 | PHP 8.3+ |
| Composer | 2.x | Latest |
| MySQL/MariaDB | MySQL 8.0 | MySQL 8.0+ |
| Node.js | v18+ | v20+ LTS |
| NPM | v10+ | Latest |
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
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)
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
├── 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
Artisan — Laravel का built-in command-line tool। Models, Controllers, Migrations, Seeders — सब एक command में generate। Development speed 10x।
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();
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_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() helper से
env("APP_NAME"); // "MyApp"
env("DB_HOST", "localhost"); // Default value
// config() helper से (better way)
config("app.name"); // "MyApp"
config("database.default"); // "mysql"
?>
// 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!"
?>
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
| Command | काम |
|---|---|
| php artisan serve | Dev server start |
| php artisan key:generate | App key set करो |
| php artisan make:model X -mcr | Model+Migration+Controller+Resource |
| php artisan migrate | DB migrations run |
| php artisan migrate:fresh --seed | Fresh DB + seed data |
| php artisan route:list | All routes show |
| php artisan tinker | Interactive PHP shell |
| php artisan optimize:clear | All caches clear |
| php artisan config:cache | Config 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 होते हैं।