承接 mystamyst/tablenice 相关项目开发

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

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

mystamyst/tablenice

Composer 安装命令:

composer require mystamyst/tablenice

包简介

Effortlessly create beautiful, interactive data tables for your Laravel applications with this intuitive Livewire component. Built with Tailwind CSS and Alpine.js, it delivers a seamless developer experience while providing users with responsive, feature-rich tables that enhance any web application.

README 文档

README

TableNice is a powerful, themeable, and highly configurable datatable and form system for Laravel, built on the modern TALL stack (Tailwind CSS, Alpine.js, Livewire, Laravel). It provides a fluent, object-oriented, and developer-friendly API to create beautiful and interactive data-driven UIs with minimal effort.

Features

  • 🚀 Fluent & Declarative API: Define your tables and forms entirely in PHP using expressive, chainable methods.
  • 🎨 Powerful Theming Engine: Choose from multiple pre-built color themes or create your own. A single line of code changes the entire look and feel.
  • DataSource Agnostic: Works seamlessly with Eloquent models, custom queries, and even API-driven collections.
  • 🎛️ Rich Column Types: Includes Text, Number, DateTime, Image, Icon, and Relation columns out of the box, each with specialized formatters and options.
  • Interactive Actions: Create row, page, and bulk actions with built-in support for forms in modals and confirmation dialogs.
  • 📈 Data Visualization: Display summary cards with dynamically generated charts (bar, line, pie, doughnut) to provide key insights at a glance.
  • Advanced Table Features: Includes global searching, per-column filtering, sorting, grouping, summary rows, and customizable pagination.
  • 🤖 Code Generation: Comes with a make:datatable command to instantly scaffold your tables and a tablenice:install command to get set up quickly.
  • 🛡️ Type-Safe by Design: Leverages modern PHP Enums for icons and colors, providing autocompletion and preventing common errors.
  • 🧩 Component-Based: Built with a clean separation of concerns using Livewire and Blade components for maximum flexibility and reusability.
  • 📱 Fully Responsive: Designed with a mobile-first approach to ensure a seamless experience on any device.

Installation & Setup

1. Require the Package

First, install the package via composer:

composer require mystamyst/tablenice -W

2. Run the Install Command

TableNice comes with a handy installation command that publishes the necessary assets and provides you with the next steps.

php artisan tablenice:install

This command will:

  • Publish the tablenice.php configuration file to your config/ directory.
  • Publish a DatatablePage.php Livewire component and its corresponding view. These are required to use the --route option in the make:datatable command.
  • Automatically detect your Tailwind CSS version and provide appropriate configuration instructions.
  • Provide you with clear, copy-pasteable instructions for the final manual steps.

3. Frontend Dependencies

The interactive elements of TableNice, like charts, calendars, and the rich text editor, require a few frontend packages. Install these via npm:

npm install -D chart.js dayjs litepicker trix @tailwindcss/typography @popperjs/core

Then, import them in your main JavaScript file (e.g., resources/js/app.js):

// resources/js/app.js
import Chart from 'chart.js/auto';
import 'litepicker/dist/plugins/mobilefriendly';
import Litepicker from 'litepicker';
import dayjs from 'dayjs';
import 'trix';

// Make libraries globally available for Alpine.js components
window.Chart = Chart;
window.Litepicker = Litepicker;
window.dayjs = dayjs;

4. Configure Tailwind CSS Typography Plugin

TableNice requires the @tailwindcss/typography plugin for rich text formatting. The configuration depends on your Tailwind CSS version:

For Tailwind CSS v4

Add the following line to your resources/css/app.css file:

@plugin "@tailwindcss/typography";

For Tailwind CSS v3

Add the typography plugin to your tailwind.config.js file:

module.exports = {
  // ... other config
  plugins: [
    require('@tailwindcss/typography'),
    // ... other plugins
  ],
}

Note: The tablenice:install command will automatically detect your Tailwind version and provide the appropriate instructions.

5. Update Your Main Layout

For modals and alerts to work correctly across your entire application, you must add the global TableNice Livewire components to your main layout file (e.g., resources/views/layouts/app.blade.php). Place these tags just before the closing </body> tag.

    ...
    {{-- This allows TableNice to display alerts and modals anywhere in your app --}}
    <livewire:tablenice-alert />
    <livewire:tablenice-form-modal />
    <livewire:tablenice-confirmation-modal />
    @stack('tablenice-scripts')
    
    @livewireScripts
</body>

Usage

1. Generate a Datatable

Use the make:datatable command to generate a Table and its corresponding Form class.

php artisan make:datatable UserTable --model=User --route

Available Command Options

  • --model=User: (Required) The Eloquent model to use for the table. The command will inspect this model to pre-fill columns and form fields.
  • --theme=indigo: Specifies a color theme for the generated table class. Defaults to blue.
  • --route: Automatically adds a full-page route for this datatable in routes/web.php using the published DatatablePage component.
  • --force: Overwrites existing Table and Form files if they already exist.

2. Customize Your Table

Open app/DataTables/UserTable.php to configure your columns, actions, and theme.

<?php

namespace App\DataTables;

use Mystamyst\TableNice\Actions\CreateAction;
use Mystamyst\TableNice\Table;
use App\Models\User;
// ... other imports

class UserTable extends Table
{
    public string $model = User::class;

    public function columns(): array
    {
        return [
            TextColumn::make('name')
                ->sortable()
                ->searchable(),

            // ... more columns
        ];
    }
    
    // ... actions, cards, etc.
}

3. Advanced Usage: Custom Query

You can easily modify the base query for your datatable by overriding the query() method in your Table class. This is perfect for adding complex joins or default scopes.

use Illuminate\Contracts\Database\Eloquent\Builder;

public function query(): Builder
{
    // Start with the base model query and add your own logic
    return parent::query()
        ->with('posts')
        ->where('active', true);
}

4. Advanced Usage: API / Collection Data Source

TableNice is not limited to Eloquent models. You can source your data from anywhere by overriding the data() method. If this method returns a Collection, it will be used instead of the query() method.

use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Http;

public function data(): ?Collection
{
    // Example: Fetching data from an external API
    $response = Http::get('https://api.example.com/users');
    
    // Ensure each item has a unique 'id' for actions to work
    return collect($response->json('data'));
}

// You no longer need the $model property
// public ?string $model = null; 

That's it! Visit your newly created route to see your datatable.

mystamyst/tablenice 适用场景与选型建议

mystamyst/tablenice 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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