Laravel 5.5 → 12.11.1 升级记录
把一个老朋友从 5.5 搬到 12.11.1, 过程全程借助 codex, 零手写代码(php多年积灰也够呛能写)。
模型使用 gpt-5.2-codex
Token usage: total=255,170 input=228,065 (+ 4,059,264 cached) output=27,105 (reasoning 12,608)
目标
把旧的 personal-blog 迁移到新的 personal-blog-new,保持功能不变,逐步适配 Laravel 12。
过程纪要
1) 新建12.x项目模板
选择 Laravel 12.11.1 的全新骨架作为承载点,保持目录结构与默认配置。
2) 迁移核心代码
- 路由改为类路由写法
- 控制器、请求、观察者、Handlers 直接迁移并做少量适配
- helpers 使用
Str::limit()和Str::random()替换旧函数 HashIdHelper兼容新版本的resolveRouteBinding签名
3) 模型与数据库层
$dates改为$casts- topics 表迁移为新的 class-based migration
- 用户表补上
avatar字段 - 工厂/种子升级为 12.x 的 class 结构
4) 视图与静态资源
保持原有 asset() 方式与 public 资源结构,先保证页面能稳定跑起来:
- views 全量迁移
- public 下 css/js/fonts/uploads 迁移
- resources/assets 迁移(暂不切 Vite)
5) 依赖与配置
迁移并补齐配置文件:
config/purifier.phpconfig/hashids.php
修复:
- Hashids
length必须是 int,不能是字符串
遇到的问题
- sessions 表不存在 - 因为
SESSION_DRIVER=database,需要运行php artisan session:table+php artisan migrate - Hashids 类型错误 - 配置里
length误写为字符串,导致TypeError
codex plan 如下
Migration Plan (Laravel 12.11.1)
Goals
- Move the current Laravel 5.5 codebase into the Laravel 12.11.1 skeleton in
personal-blog-new. - Keep behavior consistent while updating deprecated APIs and packages.
- Establish a stable, repeatable local dev environment.
Phases
- Use the existing Laravel 12.11.1 scaffold in
personal-blog-new/. - Port core PHP code: routes, controllers, models, requests, observers, helpers.
- Migrate database layer: migrations, seeders, factories (class-based).
- Update dependencies: replace/remove deprecated packages, align with PHP 8.2+.
- Migrate views and assets; decide on Vite vs. keeping Mix.
- Validate features: manual checks + tests.
- Validate features: manual checks + tests.
Key Files to Update
routes/web.phpapp/Http/Controllers/*app/Models/*,app/Models/Traits/*app/Observers/*app/Handlers/*bootstrap/helpers.phpdatabase/migrations/*,database/seeders/*,database/factories/*resources/views/*,resources/assets/*
Known API Changes
str_limit()->Str::limit()str_random()->Str::random()$dates->$castsfideloper/proxyremoved (Laravel 12 has built-in proxies)
Dependencies to Review
mews/purifierovertrue/laravel-langvinkla/hashids
Environment Notes
- PHP 8.2+ required for Laravel 12.
- MySQL and Docker compose are available for local dev.