laravel-upgrade
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseLaravel Upgrade
Laravel 版本升级
Upgrade Laravel applications one major version at a time. Supports: 9→10, 10→11, 11→12.
一次将Laravel应用升级一个主版本。支持:9→10、10→11、11→12。
Workflow
工作流程
1. Detect Current Version
1. 检测当前版本
Read and find the version constraint:
composer.jsonlaravel/frameworkphp
// Example: "laravel/framework": "^10.0" means Laravel 10.xDetermine target version (current + 1). If already on Laravel 12, inform user they're on the latest supported version.
读取并查找的版本约束:
composer.jsonlaravel/frameworkphp
// 示例:"laravel/framework": "^10.0" 表示 Laravel 10.x确定目标版本(当前版本+1)。如果当前已是Laravel 12,则告知用户当前使用的是支持的最新版本。
2. Load Upgrade Guide
2. 加载升级指南
Based on detected versions, read the appropriate reference file:
| Current | Target | Reference File |
|---|---|---|
| 9.x | 10.x | references/from-9-to-10.md |
| 10.x | 11.x | references/from-10-to-11.md |
| 11.x | 12.x | references/from-11-to-12.md |
根据检测到的版本,读取对应的参考文件:
| 当前版本 | 目标版本 | 参考文件 |
|---|---|---|
| 9.x | 10.x | references/from-9-to-10.md |
| 10.x | 11.x | references/from-10-to-11.md |
| 11.x | 12.x | references/from-11-to-12.md |
3. Scan and Fix
3. 扫描与修复
For each breaking change in the guide, scan the codebase and apply fixes:
High Impact (always check):
- dependency versions
composer.json - PHP version requirements
- Database migrations using deprecated methods
Medium Impact (check relevant files):
- Model property →
$dates(9→10)$casts - Database expressions with casting (9→10)
(string) - Column modification migrations missing attributes (10→11)
- trait behavior change (11→12)
HasUuids
Low Impact (check if patterns found):
- Deprecated method calls (,
Bus::dispatchNow, etc.)Redirect::home - Contract interface changes
- Configuration file updates
针对指南中的每一项破坏性变更,扫描代码库并应用修复:
高影响(必须检查):
- 依赖版本
composer.json - PHP版本要求
- 使用已弃用方法的数据库迁移
中影响(检查相关文件):
- 模型属性 →
$dates(9→10)$casts - 带有强制转换的数据库表达式(9→10)
(string) - 缺少属性的列修改迁移(10→11)
- trait行为变更(11→12)
HasUuids
低影响(如果发现对应模式则检查):
- 已弃用方法调用(、
Bus::dispatchNow等)Redirect::home - 契约接口变更
- 配置文件更新
4. Update Dependencies
4. 更新依赖
After code fixes, update :
composer.jsonbash
undefined完成代码修复后,更新:
composer.jsonbash
undefinedUpdate laravel/framework constraint to target version
将laravel/framework约束更新为目标版本
Update related packages per upgrade guide
根据升级指南更新相关包
composer update
undefinedcomposer update
undefined5. Post-Upgrade Verification
5. 升级后验证
- Run to verify framework boots
php artisan - Run test suite if available
- Check for deprecation warnings in logs
- 运行验证框架能否正常启动
php artisan - 如果有测试套件则运行测试
- 检查日志中的弃用警告
Common Patterns
常见模式
Dependency Updates (all upgrades)
依赖更新(所有升级通用)
Search for outdated constraints and update per guide.
composer.json在中搜索过时的约束并根据指南进行更新。
composer.jsonModel $dates to $casts (9→10)
模型$dates转为$casts(9→10)
php
// Before
protected $dates = ['deployed_at'];
// After
protected $casts = ['deployed_at' => 'datetime'];Search pattern:
protected \$dates\s*=php
// 升级前
protected $dates = ['deployed_at'];
// 升级后
protected $casts = ['deployed_at' => 'datetime'];搜索模式:
protected \$dates\s*=Database Expression Casting (9→10)
数据库表达式强制转换(9→10)
php
// Before
$string = (string) DB::raw('select 1');
// After
$string = DB::raw('select 1')->getValue(DB::connection()->getQueryGrammar());php
// 升级前
$string = (string) DB::raw('select 1');
// 升级后
$string = DB::raw('select 1')->getValue(DB::connection()->getQueryGrammar());Column Modification (10→11)
列修改(10→11)
Migrations using must now include all modifiers:
->change()php
// Before (implicit retention)
$table->integer('votes')->nullable()->change();
// After (explicit)
$table->integer('votes')->unsigned()->default(1)->nullable()->change();使用的迁移现在必须包含所有修饰符:
->change()php
// 升级前(隐式保留)
$table->integer('votes')->nullable()->change();
// 升级后(显式声明)
$table->integer('votes')->unsigned()->default(1)->nullable()->change();HasUuids Trait (11→12)
HasUuids Trait(11→12)
php
// Before (ordered UUIDv4)
use Illuminate\Database\Eloquent\Concerns\HasUuids;
// After (if you need UUIDv4 behavior)
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids as HasUuids;php
// 升级前(有序UUIDv4)
use Illuminate\Database\Eloquent\Concerns\HasUuids;
// 升级后(如果需要UUIDv4行为)
use Illuminate\Database\Eloquent\Concerns\HasVersion4Uuids as HasUuids;