PHP code example of givanov95 / laravel-data-table
1. Go to this page and download the library: Download givanov95/laravel-data-table 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/ */
// Enum filtering by case name
$table->setEnumColumn('status', App\Enums\OrderStatus::class);
// Numeric-only filtering (currency / numeric input)
$table->setPriceColumn('price');
// Date filtering with timezone-aware parsing
$table->setDateColumn('created_at', 'd.m.Y H:i:s');
$table->process(null, function ($query) {
$query->where('owner_id', auth()->id());
});
// Or for free-form mutations:
$table->advancedSearch(fn ($q) => $q->whereJsonContains('tags', 'featured'));
$table
// A select of the enum's cases: by value, labelled by the case's label() when it has one.
->setColumn('status', __('Status'), filterable: true)
->setEnumColumn('status', BookingStatus::class)
// A select of the app's options: a list of ['value' => …, 'label' => …], a
// value => label map, or a closure returning either (run once).
->setColumn('staff_id', __('Staff'), filterable: true)
->setFilterOptions('staff_id', fn () => $business->staff()->pluck('name', 'id')->all())
// A range of days: filter[starts_at][from]=2026-10-01&filter[starts_at][to]=2026-10-31.
->setColumn('starts_at', __('Starts'), orderable: true, filterable: true)
->setDateColumn('starts_at', 'd.m.Y H:i')
// Anything else is a text: contains, or equals with exactMatch.
->setRelationColumn(new RelationColumn('customer.name', __('Customer'), filterable: true));
$table->allowTrashed(); // anyone who sees the list
$table->allowTrashed(ability: 'viewArchive'); // Gate::allows('viewArchive', Post::class)
// routes/web.php
Route::post('posts/{id}/restore', [PostController::class, 'restore'])->name('posts.restore');
// PostController
public function restore(int $id)
{
return $this->posts->table()->restore($id, fn ($q) => $q->where('team_id', auth()->user()->team_id));
}
$staff = $table->restoreRecord($id, before: function (Staff $staff) use ($business) {
if (! $business->hasFreeStaffSeat()) {
throw ValidationException::withMessages(['staff' => __('No free seat on the plan.')]);
}
});
return back()->with('success', __('Staff member restored.'));