edupham/fillable

Artisan 命令获取表字段

dev-master 2023-11-25 18:32 UTC

This package is auto-updated.

Last update: 2024-09-25 20:21:06 UTC


README

该包帮助开发者通过命令行查看数据库中的表及其字段的列表。

此外,您可以使用这些字段来在模型中声明 fillable。

注意:该包处理 MySQL 和 MariaDB 数据库。

安装

运行命令

composer require edupham/fillable:dev-master

或者,如果您只想在开发环境中安装,请运行以下命令

composer require --dev edupham/fillable:dev-master

对于 Laravel 5.4.x 及以前版本,您必须在 config/app.php 文件中进行配置,并在 providers 数组中找到配置段,然后添加以下代码以注册到系统中

'providers' => [
    ...
    \Edupham\Fillable\EduphamFillableServiceProvider::class,
    ...
]

对于 Laravel 5.5.x 及以后版本,系统会自动注册,因此无需配置。

功能

1. 查看表列表

包括以下选项

  • default: 将显示数据库中的表名及其编号
  • record: 将显示数据库中的表名及其编号和现有记录数。默认情况下,结果按表名升序排序。如果要按记录数降序排序,请添加选项 --order=desc
  • upper: 将表名转换为大写并显示编号
  • const: 将创建包含 const 的声明语句
  • define: 将创建包含 define 的声明语句

与选项对应的命令

- php artisan table:show-list hoặc php artisan table:show-list default
- php artisan table:show-list upper
- php artisan table:show-list record hoặc php artisan table:show-list record --order=desc
- php artisan table:show-list const
- php artisan table:show-list define

与每个选项对应的输出,例如数据库中有一个名为 users 的表

  • default: 1. users
  • record: 1. users (1000)
  • upper: 1. USERS
  • const: const TABLE_USERS = 'users';
  • define: define('TABLE_USERS', 'users');

结果将被保存到指定路径的文件中

  • storage/app/public/tables.txt

2. 查看一个表的字段列表

运行命令

php artisan table:show-field

或者

php artisan table:show-field <table_name>

示例

php artisan table:show-field

或者

php artisan table:show-field users

注意:如果未传递 <table_name>,则包将列出正在连接的数据库中的所有表,以便用户通过编号进行选择。

结果将被保存到指定路径的文件中

  • storage/app/public/fields.txt

注意

在某些情况下,如果发生与 'table' 命令相关的错误,请运行以下命令以更新类加载器

composer dump-autoload