- Have or create a Laravel project
- Install this package with
composer require arweb/laravel-datatables-editor-plugin
- Register the service provider in
config/app.php
: addarweb\DataTablesEditor\DTEServiceProvider::class
to the config array at keyprovider
- Get DataTables Editor. Since it is not free of charge, it cannot be included in this package. You could:
- Obtain a license should be obtained at DataTables Editor
- Download the PHP version's ZIP file at https://editor.datatables.net/download/
- Install with
php artisan dte2:install ~/Desktop/Editor-PHP-2.0.2.zip
- your ZIP file path may vary
-
pick a table name, it will be referred to as
[your-table]
(when dashed notation is recommended) or[YourTable]
(when CapitalizedWords notation is recommended) in this example -
create a basic config file
config/dte/[your-table].php
for your DataTables Editor<?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]', ], ], ];
-
add these two routes into
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');
-
write the following controller into
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'; }
-
add a blade view in
resources/views/[your-table]/page.blade.php
that inherits the layoutdte::default
provided by this package:@extends('dte::default') @section('above-table') This text appears above your table. @endsection @section('under-table') This text appears below your table. @endsection
-
start the server with
php artisan serve
and look athttps://127.0.0.1:[artisan-serve-port]/[your-table]
in your browser