arweb / laravel-datatables-editor-plugin
允许轻松将 DataTables Editor 集成到 Laravel。
dev-master
2021-10-12 09:42 UTC
Requires
- php: ^7.2 || ^8.0
- laravel/framework: ^6
This package is auto-updated.
Last update: 2024-09-12 15:53:53 UTC
README
安装
- 拥有或创建一个 Laravel 项目
- 使用以下命令安装此包
composer require arweb/laravel-datatables-editor-plugin - 在
config/app.php中注册服务提供者:将arweb\DataTablesEditor\DTEServiceProvider::class添加到provider键的配置数组中 - 获取 DataTables Editor。由于它不是免费提供的,所以不能包含在本包中。你可以
- 在DataTables Editor获取许可证
- 在https://editor.datatables.net/download/下载 PHP 版本的 ZIP 文件
- 使用以下命令安装
php artisan dte2:install ~/Desktop/Editor-PHP-2.0.2.zip- 你的 ZIP 文件路径可能不同
使用方法
创建一个新的 Editor
-
选择一个表名,在这个例子中它将被引用为
[your-table](建议使用破折号表示法)或[YourTable](建议使用大写单词表示法) -
为你的 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]', ], ], ];
-
将这些路由添加到
routes/web.phpRoute::get('<your-table>', '[YourTable]Controller@page') ->name('[your-table]-page'); Route::post('<your-table>', '[YourTable]Controller@api') ->name('[your-table]-api');
-
将以下控制器写入
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'; }
-
在
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
-
使用
php artisan serve启动服务器,然后在浏览器中查看https://127.0.0.1:[artisan-serve-port]/[your-table]