Files
rxthinkcmf-wiki/RXThinkCMF_Laravel13_NaiveVue/zh/appendix/commands.md
T
2026-10-08 17:50:29 +08:00

106 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# K. Artisan 命令速查
:::tip 概述
本页汇总项目常用的 `php artisan` 命令,分为**项目自定义命令**与**框架高频命令**两部分。完整清单执行 `php artisan list` 查看(当前共 127 条)。
:::
## 项目自定义命令
| 命令 | 说明 |
|------|------|
| `php artisan generate:code {表名}` | 代码生成器 CLI(支持 `--dry-run` 预览、`--output` 导出配置、`--config` 读取配置),详见 [10.2 CLI 命令行使用](/zh/generator/cli.html) |
| `php artisan job:run` | 执行所有待执行的定时任务(配合 crontab 每分钟调用) |
| `php artisan job:daemon` | 定时任务常驻进程调度器(`--stop` 停止,锁文件 `storage/app/job_daemon.lock`) |
| `php artisan db:migrate` | 跨数据库迁移工具(`--src-*` / `--dst-*` 连接参数、`--drop-target-first`、`--tables`),详见 [7.6 数据库迁移工具](/zh/tools/db-migrate.html) |
| `php artisan dict:clear-cache` | 清除全部字典缓存 |
## 开发与调试
| 命令 | 说明 |
|------|------|
| `php artisan serve` | 启动开发服务器(默认 `127.0.0.1:8000`,可加 `--port=8080`) |
| `composer dev` | 并行启动 artisan serve + queue:listen + pail + vite |
| `php artisan tinker` | 交互式 REPL(测试模型、服务、辅助函数) |
| `php artisan pail` | 实时查看应用日志(`storage/logs/`) |
| `php artisan test` | 运行测试(等价 `composer test`,phpunit.xml 使用 sqlite 内存库) |
| `php artisan about` | 显示框架/应用基础信息 |
| `php artisan env` | 显示当前运行环境(APP_ENV) |
| `php artisan config:show [key]` | 查看某个配置项的实际生效值 |
## 缓存与性能
| 命令 | 说明 |
|------|------|
| `php artisan config:cache` | 编译配置缓存(生产) |
| `php artisan config:clear` | 清除配置缓存 |
| `php artisan route:cache` | 编译路由缓存(生产) |
| `php artisan route:clear` | 清除路由缓存 |
| `php artisan view:cache` | 预编译 Blade 视图 |
| `php artisan view:clear` | 清除编译视图 |
| `php artisan cache:clear` | 清除应用缓存 |
| `php artisan optimize` | 一次性缓存框架引导 + 配置 + 元数据 |
| `php artisan optimize:clear` | 清除以上全部缓存 |
:::warning 生产更新流程
更新代码后依次执行:`cache:clear` → `config:clear` → `route:clear` → `view:clear` → `dict:clear-cache`,再按需 `config:cache` / `route:cache` 重建(见 [11.1 部署 Checklist](/zh/deploy/checklist.html))。
:::
## 路由与数据库
| 命令 | 说明 |
|------|------|
| `php artisan route:list` | 列出全部路由(方法、URI、控制器方法) |
| `php artisan migrate` | 执行数据库迁移(**本项目 `database/migrations/` 为空,表结构以 `document/` SQL 导入为准**) |
| `php artisan migrate:status` | 查看迁移执行状态 |
| `php artisan migrate:fresh` | 重建全部表(含迁移的表) |
| `php artisan db:seed` | 执行种子数据(`DatabaseSeeder`) |
| `php artisan db:show` / `db:table {表}` | 查看数据库 / 表结构信息 |
| `php artisan key:generate` | 生成 `APP_KEY` |
## 队列
| 命令 | 说明 |
|------|------|
| `php artisan queue:work` | 消费队列(生产,配合 Supervisor) |
| `php artisan queue:listen` | 监听队列(开发,自动重启) |
| `php artisan queue:failed` | 查看失败任务 |
| `php artisan queue:retry {id}` | 重试失败任务 |
| `php artisan queue:clear` | 清空队列 |
## 定时调度(Laravel Scheduler)
| 命令 | 说明 |
|------|------|
| `php artisan schedule:list` | 查看已注册的调度任务 |
| `php artisan schedule:run` | 执行到期任务(cron 入口,每分钟调用) |
| `php artisan schedule:work` | 本地常驻调度(开发调试) |
:::info 本项目的任务调度
RXThinkCMF 业务定时任务使用自研 `job` 模块(`job:run` / `job:daemon`),Laravel Scheduler 当前仅含框架自带的 `inspire` 演示任务(见 `routes/console.php`)。
:::
## 维护与其它
| 命令 | 说明 |
|------|------|
| `php artisan down` | 进入维护模式(返回 503) |
| `php artisan up` | 退出维护模式 |
| `php artisan storage:link` | 创建上传目录软链接(`public/storage` → `storage/app/public`) |
| `php artisan event:list` | 查看事件与监听器 |
| `php artisan package:discover` | 发现并缓存扩展包(composer post-autoload-dump 自动执行) |
## Composer 脚本
| 命令 | 说明 |
|------|------|
| `composer setup` | 一键初始化(install → 复制 .env → key:generate → migrate → npm install/build) |
| `composer dev` | 开发模式并行启动(server / queue / logs / vite) |
| `composer test` | 清配置缓存 + 运行测试 |
| `./vendor/bin/pint` | 代码风格格式化(提交前执行,`pint --test` 仅检查) |
## 相关文档
- [2.3 后端服务启动](/zh/quickstart/backend-start.html)
- [6.11 定时任务](/zh/modules/job.html)
- [11.4 后端部署](/zh/deploy/backend.html)