承接 advicepharmagroup/tablegenerator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

advicepharmagroup/tablegenerator

最新稳定版本:1.1.0

Composer 安装命令:

composer require advicepharmagroup/tablegenerator

包简介

A table generator to be used with react js

README 文档

README

Latest Version on Packagist Total Downloads

A package to create a structured jason that should be consumed with a react component.

Requirements

You have to install:

Installation

You can install the package via composer:

composer require advicepharma/tablegenerator

Basic Usage

use Advicepharma\Tablegenerator\Tablegenerator;
use Advicepharma\Tablegenerator\Elements\Action;
use Advicepharma\Tablegenerator\Elements\Column;
use Advicepharma\Tablegenerator\Elements\ActionColumn;
use Spatie\QueryBuilder\QueryBuilder;

$users = QueryBuilder::for(App\Models\User::class);

$table = new Tablegenerator;
$table->query($users)
        ->paginate()
        ->addFilter()
        ->addSorts()
        ->table()
        ->addColumn(
            [
                (new Column)
                    ->field('id')
                    ->label('ID')
                    ->filtrable()
                    ->sortable(),

                (new Column)
                    ->field('name')
                    ->label('Name')
                    ->filtrable()
            ]
        );

Table creation command

php artisan make:advtable TableName --model=Model

like

php artisan make:advtable UserTable --model=User

Column object

label(<string>) column label (header) field(<string>) display the field in QueryBuilder object filtrable() set the column filtrable sortable() set the column sortable

Adding column

Adding column accpets array of Column or Column object.

$table->->table()
        ->addColumn(
            [
                (new Column)
                    ->field('name')
                    ->label('Name'),
                (new Column)
                    ->field('email')
                    ->label('Email')
            ]
        )

or:

$table->->table()
        ->addColumn(
            (new Column)
                ->field('name')
                ->filterKey('name')
                ->label('Name')
                ->filtrable()
                ->sortable()
        )

Action column

Action column are used to render actions in the table. Default action are edit and delete:

(new ActionColumn)
    ->label('')
    ->addAction(
        (new Action)
            ->type(Action::ACTION_EDIT)
            ->properties(
                [
                    'link_to' => '/account/users/#id#'
                ]
            )
    )
    ->addAction(
        (new Action)
            ->type(Action::ACTION_DELETE)
            ->properties(
                [
                    'confirm' => true,
                    'confirm_message' => 'Do you really want to delete this user?',
                    'link_to' => route('user.destroy', '#id#', false)
                ]
            )
    )

type can be whatever you want: this two are the default one.

properties can contains all the properties that are going to be consumed by frontend

Pagination

Pagination is super easy: you have to add ->paginate() to create default pagination structure. If you want, you can specify the pagesize passing an integer value ->paginate(100)

Api resource

If you want to use ApiResource feature, you can add it with

$table->->table()
    ->withResource(YourResource::class)

Relationship column

If you are working with a QueryBuilder with relationship, like:

QueryBuilder::for(App\Models\Post::class)->with('user');

Al you need to do is to specify the colum field with dot notation:

(new Column)->field('user.name')->label('User Name')

If you want to filter a related field, you need to add filterKey('user.name') (or whatever table.field value you want to search)

Unforturnately sorting a relation field is not yet supported

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email giacomo.garavaglia@advicepharma.com instead of using the issue tracker.

Credits

License

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

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-07