Laravel 1.x 是该框架的初始版本(发布于 2011 年),其核心特性体现了早期设计理念:
1. 路由系统
采用简洁的闭包路由定义方式:
php
Route::get('home', function() {
return View::make('home');
});
支持基础的路由参数匹配(如 Route::get('user/(:num)', ...))。
2. 视图与模板
-
通过
View::make()渲染原生 PHP 模板 -
支持基础的数据传递:
phpreturn View::make('profile')->with('name', 'Taylor');
3. 数据库操作
-
提供
Query类执行原始 SQL:php$users = DB::query('SELECT * FROM users'); -
初步封装了查询构造器雏形:
phpDB::table('users')->where('id', '=', 1)->get();
4. ORM 雏形 (Eloquent)
-
基础 ActiveRecord 实现:
phpclass User extends Eloquent {} -
支持简单查询:
php$user = User::find(1);
5. 依赖注入容器
-
初步实现 IoC 容器:
phpApp::bind('mailer', function() { return new Mailer; });
局限性
- 功能缺失:无中间件、事件系统、队列等现代组件。
- 模板引擎:未集成 Blade,需直接使用 PHP 文件。
- 扩展性弱:模块化设计不如后续版本完善。
版本演进
- Laravel 1.x 生命周期较短(2011.06--2012.10),后续由 2.x 版本引入命名空间等重大改进。