Skills2026年4月12日·1 分钟阅读

Laravel — The PHP Framework for Web Artisans

Laravel is an expressive, elegant PHP web framework. Provides routing, Eloquent ORM, Blade templates, queues, events, broadcasting, and a rich ecosystem (Forge, Vapor, Nova, Livewire). The most popular PHP framework by a wide margin.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
直接安装命令
npx -y tokrepo@latest install cc164e67-362e-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
Laravel is the most popular PHP web framework, providing Eloquent ORM, Blade templates, queues, events, broadcasting, and a comprehensive ecosystem.
§01

What it is

Laravel is a PHP web framework with an expressive, elegant syntax. It provides routing, Eloquent ORM for database operations, Blade template engine, queue management, event broadcasting, task scheduling, and authentication scaffolding. The ecosystem includes Forge (server management), Vapor (serverless deployment), Nova (admin panel), Livewire (reactive components), and Jetstream (starter kit).

Laravel targets PHP developers building web applications, APIs, and backend services. It is the most popular PHP framework by adoption, with a large community, extensive documentation, and a mature ecosystem of first-party and community packages.

§02

How it saves time or tokens

Laravel's artisan CLI generates models, controllers, migrations, and tests with single commands. Eloquent ORM maps database tables to PHP classes without manual SQL. Built-in features like authentication, rate limiting, and email sending eliminate common boilerplate. The Blade template engine compiles to plain PHP for zero-overhead rendering.

§03

How to use

  1. Create a new project: composer create-project laravel/laravel my-app.
  2. Start the development server: cd my-app && php artisan serve.
  3. Generate models, controllers, and migrations with artisan: php artisan make:model Post -mcr.
§04

Example

# Create a new Laravel project
composer create-project laravel/laravel my-app
cd my-app
php artisan serve
# Visit http://localhost:8000

# Generate a model with migration and controller
php artisan make:model Post -mcr
// routes/api.php
Route::apiResource('posts', PostController::class);

// app/Http/Controllers/PostController.php
public function index()
{
    return Post::with('author')
        ->where('published', true)
        ->orderBy('created_at', 'desc')
        ->paginate(20);
}

public function store(Request $request)
{
    $validated = $request->validate([
        'title' => 'required|max:255',
        'body' => 'required',
    ]);
    return Post::create($validated);
}
§05

Related on TokRepo

§06

Common pitfalls

  • Laravel's magic (auto-resolution, implicit model binding, accessors/mutators) can be confusing for newcomers. Read the documentation thoroughly before relying on conventions.
  • Eloquent's eager loading (with()) is critical for performance. Without it, N+1 query problems silently degrade performance on collection pages.
  • Laravel major version upgrades (e.g., 10 to 11) include breaking changes. Use the upgrade guide and test thoroughly before upgrading production applications.

常见问题

How does Laravel compare to Symfony?+

Laravel provides more built-in features and conventions out of the box, making it faster to start. Symfony is more modular and flexible, preferred for large enterprise applications. Laravel uses several Symfony components under the hood.

Does Laravel support API development?+

Yes. Laravel provides API-specific routing, resource controllers, API authentication (Sanctum, Passport), rate limiting, and JSON response helpers. Laravel is commonly used as a backend API for SPA and mobile applications.

What is Eloquent ORM?+

Eloquent is Laravel's ActiveRecord ORM that maps database tables to PHP classes. Each model represents a table, and you use method chains to query, insert, update, and delete records without writing SQL.

Can Laravel be used for real-time applications?+

Yes. Laravel supports WebSocket broadcasting through Laravel Echo and Pusher or Soketi. Events are broadcast in real-time to frontend applications. This enables chat, notifications, and live updates.

Is Laravel free?+

Yes. Laravel is open source under the MIT license. The ecosystem tools (Forge, Vapor, Nova) are paid products, but the framework itself and most community packages are free.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产