PHP code example of qbits / laravel-inertia-vue-datatable
1. Go to this page and download the library: Download qbits/laravel-inertia-vue-datatable library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
qbits / laravel-inertia-vue-datatable example snippets
use YourVendor\InertiaDataTable\Traits\HasDataTable;
class UserController extends Controller
{
use HasDataTable;
private function columns(): array
{
return [
['key' => 'id', 'label' => 'ID', 'sortable' => true, 'searchable' => false, 'exportable' => true],
['key' => 'name', 'label' => 'Name', 'sortable' => true, 'searchable' => true, 'exportable' => true],
['key' => 'email', 'label' => 'Email', 'sortable' => true, 'searchable' => true, 'exportable' => true],
];
}
public function index()
{
$query = User::query();
$tableData = $this->dataTable($query, $this->columns());
return Inertia::render('Users/Index', [
'table' => $tableData,
]);
}
public function export(Request $request)
{
$ids = array_filter(explode(',', $request->input('ids', '')));
$format = $request->input('format', 'xlsx');
$query = User::query();
return Excel::download(
new DataTableExport($query, $this->columns(), $ids),
'users.' . $format
);
}
public function bulkDestroy(Request $request)
{
User::whereIn('id', $request->ids)->delete();
return back();
}
}
Route::get('/users', [UserController::class, 'index']);
Route::get('/users/export', [UserController::class, 'export']);
Route::delete('/users/bulk-destroy', [UserController::class, 'bulkDestroy']);
return [
'per_page' => 15,
'per_page_options' => [10, 15, 25, 50, 100],
'export_filename' => 'export',
];
bash
php artisan vendor:publish --tag=datatable-config
php artisan vendor:publish --tag=datatable-components