arweb/laravel-datatables-editor-plugin

允许轻松将 DataTables Editor 集成到 Laravel。

dev-master 2021-10-12 09:42 UTC

This package is auto-updated.

Last update: 2024-09-12 15:53:53 UTC


README

安装

  1. 拥有或创建一个 Laravel 项目
  2. 使用以下命令安装此包composer require arweb/laravel-datatables-editor-plugin
  3. config/app.php中注册服务提供者:将 arweb\DataTablesEditor\DTEServiceProvider::class 添加到 provider 键的配置数组中
  4. 获取 DataTables Editor。由于它不是免费提供的,所以不能包含在本包中。你可以
    1. DataTables Editor获取许可证
    2. https://editor.datatables.net/download/下载 PHP 版本的 ZIP 文件
    3. 使用以下命令安装php artisan dte2:install ~/Desktop/Editor-PHP-2.0.2.zip - 你的 ZIP 文件路径可能不同

使用方法

创建一个新的 Editor

  1. 选择一个表名,在这个例子中它将被引用为 [your-table](建议使用破折号表示法)或 [YourTable](建议使用大写单词表示法)

  2. 为你的 DataTables Editor 创建一个基本的配置文件 config/dte/[your-table].php

    <?php
    return [
        'routeName' => '[your-table]-api',
        'databaseConnection' => '[your-laravel-database-connection-identifier]',
        'mainTable' => '[name-of-your-table-in-your-database-system]',
        'fields' => [
            '[text-field-name]' => ['type' => 'text', 'label' => '[text field name]'],
            '[enum-field-name]' => [
                'type' => 'select',
                'options' => [
                    'Option 1 Label' => 'Option1EnumValue',
                    'Option 2 Label' => 'Option2EnumValue',
                    'Option 3 Label' => 'Option3EnumValue',
                ],
                'label' => '[enum field name]',
            ],
        ],
    ];
  3. 将这些路由添加到 routes/web.php

       Route::get('<your-table>', '[YourTable]Controller@page')
       ->name('[your-table]-page');
       Route::post('<your-table>', '[YourTable]Controller@api')
       ->name('[your-table]-api');
  4. 将以下控制器写入 app/Http/Controllers/[YourTable]Controller.php

    <?php
    
    namespace App\Http\Controllers;
    
    use arweb\DataTablesEditor\DTEController;
    
    class [YourTable]Controller extends DTEController
    {
        protected $editorConfigKey = 'dte.<your-table>';
        protected $editorViewFile = '[your-table]/page';
    }
  5. resources/views/[your-table]/page.blade.php 中添加一个 blade 视图,它继承自本包提供的布局 dte::default

    @extends('dte::default')
    
    @section('above-table')
    This text appears above your table.
    @endsection
    
    @section('under-table')
    This text appears below your table.
    @endsection
  6. 使用 php artisan serve 启动服务器,然后在浏览器中查看 https://127.0.0.1:[artisan-serve-port]/[your-table]