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 先选择当前运行时、检查安装计划,再运行匹配命令。
npx -y tokrepo@latest install cc164e67-362e-11f1-9bc6-00163e2b0d79 --target codex先 dry-run 确认安装计划,再运行此命令。
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.
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.
How to use
- Create a new project:
composer create-project laravel/laravel my-app. - Start the development server:
cd my-app && php artisan serve. - Generate models, controllers, and migrations with artisan:
php artisan make:model Post -mcr.
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);
}
Related on TokRepo
- Coding AI Tools — Web framework and development tools
- API Tools — API framework resources
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.
常见问题
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.
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.
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.
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.
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)
- Laravel GitHub— Laravel provides routing, Eloquent ORM, Blade templates, queues, and a rich ecos…
- Laravel Documentation— Laravel documentation and feature reference
- Laravel Official Site— PHP web framework architecture and best practices
TokRepo 相关
讨论
相关资产
Symfony — The PHP Framework for Reusable Components and Web Applications
A set of decoupled PHP components and a full-stack framework for building robust web applications and APIs.
CakePHP — Rapid Development PHP Framework
A PHP framework that makes building web applications simpler and faster through conventions, code generation, and a rich built-in toolkit.
Angular — The Enterprise Web Application Framework
Angular is a comprehensive TypeScript-based web framework by Google. It provides everything needed for large-scale applications — components, routing, forms, HTTP client, dependency injection, and testing — in a single, opinionated platform.
Next.js — The Full-Stack React Framework for the Web
Next.js is the most popular React framework for building full-stack web applications. It provides server-side rendering, static generation, API routes, file-based routing, and React Server Components — making React production-ready out of the box.