定制 nion/laravel-model-datatable 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nion/laravel-model-datatable

最新稳定版本:1.0.2

Composer 安装命令:

composer require nion/laravel-model-datatable

包简介

A Laravel package for generating dynamic data tables using Blade components.

README 文档

README

A simple and powerful package for handling datatables in Laravel applications.

Installation

You can install the package via composer:

composer require nion/model-datatable

The package will automatically register its service provider.

Usage

1. Publish the configuration (optional)

php artisan vendor:publish --provider="Nion\ModelDatatable\Providers\ModelDataTableServiceProvider" --tag="config"

2. Add the trait to your model

use Nion\ModelDatatable\Traits\HasDataTable;

class User extends Model
{
    use HasDataTable;
    
    // Define your columns
    protected $datatableColumns = [
        'id' => 'ID',
        'name' => 'Name',
        'email' => 'Email',
        'created_at' => 'Created At'
    ];
}

3. In your controller

public function index()
{
    $users = User::datatable();
    
    if (request()->ajax()) {
        return $users;
    }
    
    return view('users.index', compact('users'));
}

4. In your blade view

<table id="users-table">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Email</th>
            <th>Created At</th>
        </tr>
    </thead>
</table>

@push('scripts')
<script>
$(document).ready(function() {
    $('#users-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: "{{ route('users.index') }}",
        columns: [
            {data: 'id', name: 'id'},
            {data: 'name'},
            {data: 'email'},
            {data: 'created_at'}
        ]
    });
});
</script>
@endpush

Features

  • Server-side processing
  • Automatic column handling
  • Search functionality
  • Sorting functionality
  • Pagination
  • Custom column formatting
  • Relationship handling

Configuration

You can customize the package behavior by publishing the config file:

// config/model-datatable.php
return [
    'default_per_page' => 15,
    'search_columns' => ['name', 'email'],
    'date_format' => 'Y-m-d H:i:s',
];

License

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

Laravel Model DataTable

Latest Version Total Downloads License

Laravel Model DataTable makes it easy to generate dynamic data tables directly from Eloquent models in Blade templates.

Supports:

  • Bootstrap, Tailwind, or Custom Views
  • Automatic table rendering from models
  • Customizable and extendable UI

🚀 Installation

You can install the package via Composer:

composer require nion/laravel-model-datatable

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-08