invoiceninja/inspector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

invoiceninja/inspector

Composer 安装命令:

composer require invoiceninja/inspector

包简介

Simplified database records management

README 文档

README

inspector logo

Simplified database records management. Inspector will let you take care of CRUD without taking over your frontend.

Example

$inspector = new \InvoiceNinja\Inspector\Inspector();

// List all tables in the database
$tables = $inspector->getTableNames();

// Get table columns
$columns = $inspector->getTableColumns('users');

Installation

You can install the package via composer:

composer require invoiceninja/inspector

Requirements

  • Laravel 8.x
  • PHP 7.4+

Philosophy

Inspector isn't your regular admin panel. It is meant to be used as part of the admin panel. That said, we wanted something that is lightweight and it doesn't take over your front end.

It doesn't care about your CSS framework, do you use Livewire or not, because you're in charge of integrating it. Don't worry, it's extremely simple.

Usage

Like we previously said, you're in charge of integrating Inspector, but we will give you the most simple examples here.

Start by creating one controller, we will name it TableController.

php artisan make:controller TableController

Showing tables in the database

public function index(\InvoiceNinja\Inspector\Inspector $inspector)
{
    return view('tables.index', [
        'tables' => $inspector->getTableNames(),
    ]);
}

Now, to show all these tables, you can make your own loop. To speed things up, we've provided some prebuilt components.

<x-inspector-tables :tables="$tables" />

This will show a nice preview of all tables in your database.

Tables
Failed jobs
Migrations
Password resets
Personal access tokens
Users

Awesome, let's make the link to the individual table page. We can do this by passing the show-route-name parameter in the component.

<x-inspector-tables :tables="$tables" show-route-name="tables.show" />

Note: Route name is fully optional. We're using a resourceful controller, following Laravel conventions.

By doing that, we should get a new "View" action in our table:

Table Action
Failed jobs View
Migrations View
Password resets View
Personal access tokens View
Users View

Showing table columns

It might be useful for you to preview table columns & their types. To achieve that we can use the getTableColumns method.

public function show(string $table, \InvoiceNinja\Inspector\Inspector $inspector)
{
    return view('tables.show', [
        'columns' => $inspector->getTableColumns($table),
    ]);
}
<x-inspector-columns :columns="$columns" />

That will produce a nice table with all columns/types.

Column Type
id integer
migration string
batch integer

Showing table records

To show table records, we can make use of the getTableRecords method.

public function show(string $table, \InvoiceNinja\Inspector\Inspector $inspector)
{
    return view('tables.show', [
        'table' => $inspector->getTableSchema($table),
        'columns' => $inspector->getTableColumns($table),
        'records' => $inspector->getTableRecords($table),
    ]);
}
<x-inspector-records 
    :table="$table" 
    :columns="$columns"
    :records="$records" /> 

To generate a link to a specific record, pass show-route-name:

<x-inspector-records 
    :table="$table" 
    :columns="$columns"
    :records="$records"
    show-route-name="tables.edit" /> 

This will generate URL like this: /tables/{table}/edit?id=1.

# id migration batch
View 1 2014_10_12_000000_create_users_table 1

Showing & editing row in the table

Showing a page for the specific row is super simple. We can make use of the getTableRecord method.

public function edit(string $table, \Illuminate\Http\Request $request, \InvoiceNinja\Inspector\Inspector $inspector)
{
    return view('tables.edit', [
        'table' => $inspector->getTableSchema($table),
        'columns' => $inspector->getTableColumns($table),
        'record' => $inspector->getTableRecord($table, $request->query('id')),
    ]);
}
<x-inspector-record 
    :record="$record" 
    :table="$table"
    :columns="$columns"
    update-route-name="tables.update" />

This will generate the form with all columns as input fields & their values as part of input values.

Note: update-route-name is optional.

Updating table row

One thing that is left is updating the table row. As you can probably guess, Inspector provides a helper method - updateTableRecord.

public function update(string $table, \Illuminate\Http\Request $request, \InvoiceNinja\Inspector\Inspector $inspector)
{
    $inspector->validate($request, $table);

    $success = $inspector->updateTableRecord($table, $request->query('id'), $request);

    if ($success) {
        return back()->withMessage('Successfully updated the record.');
    }

    return back()->withMessage('Oops, something went wrong.');
}

Configuration

We did our best to make Inspector as configurable as possible. To tinker with a configuration file, make sure to publish it first.

php artisan vendor:publish --provider="InvoiceNinja\Inspector\InspectorServiceProvider"

With configuration published, you can control visible tables, as well as hidden, component classes & modify them as you wish.

Available methods

  • setConnectionName(string $connectionName): self - Set the database connection. By default it will pick up your default app connection.

  • getConnectionName(): string - Retrieve the current connection name.

  • getSchemaManager(): Doctrine\DBAL\Schema\AbstractSchemaManager - Retrieve current schema manager instance.

  • getTableNames(): array - Retrieve the list of table names in the database.

  • getTableSchema(string $table): Doctrine\DBAL\Schema\Table - Retrieve Table representation of table.

  • getTableColumns(string $table): array - Retrieve all columns for specified table.

  • getTable(string $table): Illuminate\Database\Query\Builder - Table instance of query builder.

  • getTableRecords(string $table, array $columns = ['*']): Illuminate\Support\Collection - Retrieve all records for the specified table.

  • getTableRecord(string $table, string $value, string $column = 'id'): mixed - Retrieve single record for specified table.

  • updateTableRecord(string $table, string $id, Request $request, string $column = 'id'): bool - Update specific table row.

  • validate(Request $request, string $table) - Validate specific request.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email contact@invoiceninja.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

invoiceninja/inspector 适用场景与选型建议

invoiceninja/inspector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 313.08k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2021 年 09 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「inspector」 「invoiceninja」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 invoiceninja/inspector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 invoiceninja/inspector 我们能提供哪些服务?
定制开发 / 二次开发

基于 invoiceninja/inspector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 313.08k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-09