Chuyển đến nội dung chính

Lesson 1: Introducing Laravel — The most elegant PHP framework

What is Laravel, "elegant syntax" philosophy. Compare Laravel vs Symfony vs Django vs Spring. PHP 8.4 essentials (readonly, enums, fibers, named arguments). Laravel Sail, Herd setup.

💻 Programming — Lesson 1 Lesson 1: Introducing Laravel — PHP framework The most elegant

Laravel: From Basics to Advanced

Part 1: Laravel Fundamentals

xdev.asia

1. What is Laravel?

Laravel is the most popular PHP framework, philosophically "elegant syntax" — code is clean, easy to read, developer experience comes first. Laravel provides a complete ecosystem: ORM (Eloquent), queue, cache, auth, testing, deployment.

FrameworkLanguageORMAdvantages
LaravelPHPEloquentBig ecosystem, great DX
SymfonyPHPDoctrineEnterprise, flexible
DjangoPythonDjango ORMBatteries-included, admin built-in
Spring BootJavaJPA/HibernateEnterprise, microservices

2. PHP 8.4 Essentials

<?php
// Enums
enum UserRole: string {
    case Admin = 'admin';
    case Staff = 'staff';
    case Customer = 'customer';
}

// Readonly properties
class Product {
    public function __construct(
        public readonly string $name,
        public readonly float $price,
    ) {}
}

// Named arguments
$user = User::create(
    name: 'John',
    email: '[email protected]',
    role: UserRole::Customer,
);

// Match expression
$label = match($status) {
    'active' => 'Hoạt động',
    'inactive' => 'Tạm dừng',
    default => 'Không xác định',
};

3. Install Laravel

# Với Composer
composer create-project laravel/laravel my-app

# Với Laravel Installer
composer global require laravel/installer
laravel new my-app

# Với Laravel Sail (Docker)
curl -s "https://laravel.build/my-app?with=pgsql,redis" | bash
cd my-app && ./vendor/bin/sail up

4. Folder structure

my-app/
├── app/
│   ├── Http/Controllers/
│   ├── Models/
│   └── Providers/
├── config/
├── database/
│   ├── factories/
│   ├── migrations/
│   └── seeders/
├── resources/views/
├── routes/
│   ├── web.php
│   └── api.php
├── storage/
├── tests/
├── .env
└── artisan
# Artisan commands
php artisan serve          # Dev server
php artisan make:model Product -mfc  # Model + migration + factory + controller
php artisan migrate        # Chạy migrations
php artisan tinker         # REPL

Next article: Routing, Controllers & Middleware.