stianscholtz/laravel-data-table
Composer 安装命令:
composer require stianscholtz/laravel-data-table
包简介
A Laravel package to create data tables.
README 文档
README
This headless Laravel package provides a convenient way to create and manage data tables in your Laravel applications. With support for various column types including boolean, date, enum, number, and text, it allows you to quickly set up and customize data tables to suit your needs.
Features
- Column Types: Supports boolean, date, enum, number, and text columns.
- Data Table Generation: Includes a command to generate data tables with default boilerplate in the
app/DataTablesdirectory. - Search Filtering: Support for filtering data based on the supplied search term.
- Export Functionality: Built-in functionality for easily exporting query results.
Installation
You can install the package via Composer. Simply run the following command:
composer require stianscholtz/laravel-data-table
Usage
Generating Data Tables
To generate a data table, use the provided Artisan command:
php artisan make:data-table YourDataTableProvider
Defining Data Tables
In your data table class, you define the query and columns. For example:
use Illuminate\Contracts\Database\Query\Builder; use Stianscholtz\LaravelDataTable\DataTableBuilder; use Stianscholtz\LaravelDataTable\DataTableProvider; use DB; class YourDataTableProvider extends DataTableProvider { protected bool $exportable = false; public function query(): Builder { /** @var Model $model */ $model = request()->route('model'); return DB::table('users') ->where('condition1', 'value') ->where('condition2', request('value')) ->when($model, fn(Builder $query) => $query->where('condition3', 'value')) ->select('users.id');//If you want to include the id in the data set. } public function columns(DataTableBuilder $builder): void { $builder->numberColumn('users.id', 'id', 'ID'); if (!request()->route('model')) { $builder->textColumn('model.field', 'field', 'Field Name', false); } $builder->textColumn('users.name', 'user', 'User') ->enumColumn('users.status', 'status', 'Status') ->booleanColumn('IF(users.active, \'Yes\', \'No\')', 'active', 'Active') ->dateColumn('users.updated_at', 'updated_at', 'Updated At'); } }
Controller
public function index() { return view('view.name', [ 'variable' => 'value', ...YourDataTableProvider::get(), ]); //OR return view('view.name', YourDataTableProvider::get(['variable' => 'value'])); }
Filtering Data
The package automatically handles filtering data based on the supplied search term. Simply pass a 'term' in the request, and the package will filter the data accordingly.
Exporting Data
The package automatically handles exporting data when $exportable is true and there is a 'export' key with a value of '1' in the request. The value of $exportable will also be available on the client side to determine if an export button should be visible.
Contributing
Contributions are welcome! Please feel free to submit a pull request.
License
The MIT License (MIT). Please see License File for more information.
stianscholtz/laravel-data-table 适用场景与选型建议
stianscholtz/laravel-data-table 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 12 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「data tables」 「Stian-Scholtz」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 stianscholtz/laravel-data-table 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 stianscholtz/laravel-data-table 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 stianscholtz/laravel-data-table 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
(ru) language pack for the Static Info Tables providing localized names for countries, currencies and so on.
(Ukrainian) language pack for the Static Info Tables providing localized names for countries,currencies and so on.
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Turkish (tr) language pack for the Static Info Tables providing localized names for countries.
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-13