laravel

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Laravel

Laravel

Laravel is a web application framework with expressive, elegant syntax. Laravel 11 (2025) introduces a streamlined skeleton and native WebSocket server (Reverb).
Laravel是一款语法简洁优雅的Web应用框架。Laravel 11(2025版)引入了精简的项目骨架和原生WebSocket服务器(Reverb)。

When to Use

适用场景

  • Solo Developers / Small Teams: The ecosystem (Forge, Vapor, Nova) solves devops and admin needs.
  • PHP Shops: The gold standard for modern PHP.
  • Real-time Apps: The new Reverb server makes WebSockets a first-class citizen without external Node dependencies.
  • 独立开发者/小型团队:其生态系统(Forge、Vapor、Nova)可解决DevOps和后台管理需求。
  • PHP开发团队:是现代PHP开发的黄金标准。
  • 实时应用:全新的Reverb服务器让WebSocket成为一等公民,无需依赖外部Node服务。

Quick Start

快速开始

php
// routes/web.php
Route::get('/', function () {
    return view('welcome');
});

// app/Models/User.php
// Elegant Active Record
$users = User::where('active', 1)->get();
php
// routes/web.php
Route::get('/', function () {
    return view('welcome');
});

// app/Models/User.php
// Elegant Active Record
$users = User::where('active', 1)->get();

Core Concepts

核心概念

Slim Skeleton (v11)

精简项目骨架(v11版)

Laravel 11 removed
Kernel.php
and Middleware classes. Configuration fits in
bootstrap/app.php
. Example:
php
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: ['stripe/*']);
})
Laravel 11移除了
Kernel.php
和中间件类,所有配置可整合到
bootstrap/app.php
中。示例:
php
->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: ['stripe/*']);
})

Laravel Reverb

Laravel Reverb

First-party WebSocket server written in PHP. Scalable and fast.
由PHP编写的官方WebSocket服务器,具备高可扩展性与高性能。

Ecosystem

生态系统

  • Livewire: Build dynamic UIs with PHP (similar to Hotwire/Blazor).
  • Filament: Amazing Admin/Dashboard builder built on Livewire.
  • Livewire:使用PHP构建动态UI(类似Hotwire/Blazor)。
  • Filament:基于Livewire打造的出色后台/仪表盘构建工具。

Best Practices (2025)

2025年最佳实践

Do:
  • Use Filament: For admin panels, it is vastly superior to Nova in 2025 for customizability.
  • Use
    Pest
    : The new default testing framework. It's beautiful and minimal.
  • Use
    cast()
    attributes
    : Define model casts using the method syntax for clear type conversions.
Don't:
  • Don't over-abstract: Laravel Facades (
    Route::
    ,
    DB::
    ) are fine. Don't create Repository patterns unless you actually need to swap implementations.
推荐做法
  • 使用Filament:2025年,在自定义性方面,Filament作为后台面板工具远超Nova。
  • 使用
    Pest
    :全新的默认测试框架,简洁美观。
  • 使用
    cast()
    属性
    :通过方法语法定义模型类型转换,实现清晰的类型转换逻辑。
不推荐做法
  • 过度抽象:Laravel门面(
    Route::
    DB::
    )的使用是合理的。除非确实需要切换实现方案,否则无需创建仓储模式。

References

参考资料