1.Laravelとは何ですか?
Laravel は、哲学的には最も人気のある PHP フレームワークです 「エレガントな構文」 — コードはクリーンで読みやすく、開発者のエクスペリエンスが最優先されます。 Laravel は、ORM (Eloquent)、キュー、キャッシュ、認証、テスト、デプロイメントといった完全なエコシステムを提供します。
| フレームワーク | 言語 | ORM | 利点 |
|---|---|---|---|
| ララベル | PHP | 雄弁 | 大きなエコシステム、優れた DX |
| シンフォニー | PHP | 教義 | エンタープライズ、フレキシブル |
| ジャンゴ | パイソン | ジャンゴ ORM | バッテリー付属、管理機能内蔵 |
| スプリングブーツ | ジャワ | JPA/休止状態 | エンタープライズ、マイクロサービス |
2. PHP 8.4 の基礎
<?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.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. フォルダー構造
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
次の記事: ルーティング、コントローラー、ミドルウェア。