sawmainek/apitoolz

APIToolz可以在几秒钟内根据提供的模型快速生成RESTful API。

v1.0.1 2024-05-04 17:00 UTC

This package is auto-updated.

Last update: 2024-09-04 18:11:44 UTC


README

APIToolz可以在几秒钟内根据提供的模型快速生成RESTful API,允许您无缝地将您的RESTful API文档与前端开发者共享。

功能

  • 使用AI创建解决方案
  • 通过Artisan命令创建数据库表迁移
  • 通过Artisan命令使用Create Table SQL生成RESTful API
  • Swagger API文档
  • 全文搜索功能
  • 支持API身份验证/授权
  • 支持两个模型之间的关联
  • 配置选项包括[request body]Validation, Cast[object, array], Full-text search enable, Fillable, Input Type(text, password, image/file upload, and more)
  • 配置选项包括[response body]Casting, Show/Hide, Object, Array, and more
  • 包括User Register, Login, Forget Password, Verification(email, OTP, and Authenticator - coming soon), User Profile Update, Inactive/Logout Profile的应用程序用户入门功能
  • 代码和数据库的每日自动备份
  • 请求/数据库查询/响应记录层
  • 通过Artisan命令导出/导入模型功能

要求

AP IToolz需要至少PHP 8.2和Laravel 11。

安装(使用Composer

composer require sawmainek/apitoolz

激活

安装后,使用apitoolz:activate Artisan命令和您的购买密钥dns激活APIToolz

php artisan apitoolz:activate --client-dns=http://127.0.0.1:8000 --purchase-key="demo"

如果您没有购买密钥,请从Codecanyon购买。

用法

现在,快速创建您的解决方案,然后发布您的解决方案。

php artisan apitoolz:ai --requirement="For POS system, include sale order, and cashier"

您可以使用apitoolz:model Artisan命令生成模型

php artisan apitoolz:model Product --table=products --soft-delete

如果您希望创建带有用户policy的模型,可以使用--use-policy Artisan命令。注意:模型的表有字段user_id

您还可以使用以下SQL格式生成模型

php artisan apitoolz:model Customer --table=customers --soft-delete --sql="
CREATE TABLE customers (
    id INT AUTO_INCREMENT PRIMARY KEY,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    email VARCHAR(100),
    phone_number VARCHAR(20) NOT NULL,
    address VARCHAR(255),
    city VARCHAR(100),
    state VARCHAR(50),
    country VARCHAR(100),
    zip_code VARCHAR(20)
);"

注意:--table=customers--sql="CREATE TABLE 'customers' ..."必须匹配。

生成后,您可以通过以下方式检查您的模型的RESTful API

API文档中的Swagger API文档

创建数据表

如果您只想创建数据库表,可以使用apitoolz:datatable Artisan命令。

php artisan apitoolz:datatable customers --soft-delete

要删除数据库表

php artisan apitoolz:datatable customers --remove

如果您想添加更多字段、更新和删除,您可以使用以下选项完成,使用add-field=update-field=drop-field=在Artisan命令上。

php artisan apitoolz:datatable customers --add-field=gender --type=string --field-after=email --not-null --default=other

请求体配置

配置提供的模型的字段级配置

php artisan apitoolz:request Sale --field=sale_date --validator="required|date|after:tomorrow" --searchable=false

有关请求体配置的可用选项参数

php artisan apitoolz:request {model} {--field=} {--label=} {--input-type=} {--validator=} {--cast=} {--searchable=true/false} {--fillable=true/false} {--position=} {--upload-path=} {--upload-max-size=} {--upload-type=image/file} {--upload-multiple=false/false} {--reset}

如果您想重置默认的字段配置

php artisan apitoolz:request Sale --field=sale_date --reset

模型关系

要添加两个模型之间的关联(例如,belongsTohasOnehasMany),请使用以下命令

// For belongsTo
php artisan apitoolz:relation Sale --title=customer --relation-model=Customer --relation-type=belongsTo --foreign-key=customer_id

// For hasOne
php artisan apitoolz:relation Customer --title=phone --relation-model=Phone --relation-type=hasOne

要删除提供的模型现有的关系

php artisan apitoolz:relation Customer --title=phone --remove

有关关系的其他选项

apitoolz:relation {model} {--title=} {--relation-model=}  {--relation-type=belongsTo} {--foreign-key=} {--display-field=} {--sub-relation-model=} {--remove} {--force}

重建您的RESTful API模型

php artisan apitoolz:model Customer --rebuild

删除您的模型

php artisan apitoolz:model Product --remove --remove-table

导出/导入模型

APIToolz允许您使用apitoolz:export|import Artisan命令导出/导入模型。

导出模型

php artisan apitoolz:export --include-data

导出提供的名称的模型

php artisan apitoolz:export --model=Customer --include-data

导入模型

php artisan apitoolz:import --file=your_file.zip

导入提供的名称的模型,不带数据

php artisan apitoolz:import --file=your_file.zip --model=Customer --exclude-data

许可证

商业软件许可证。