syamsoul/laravel-datatable-ssp
Laravel package to run DataTables in true server-side processing (SSP). Simplifies filtering, sorting, searching, and pagination with an API inspired by the original DataTables SSP class. Supports Laravel 9+ (PHP 8+) and integrates cleanly in controllers and views.
setColumns(), setQuery(), frontend()), allowing TPMs to incrementally adopt features (e.g., caching, exports) without refactoring entire data layers.SSP service) via constructor or method injection, adhering to Laravel’s dependency injection (DI) principles. This enables easy swapping of implementations (e.g., for testing or alternative SSP providers).$ssp->frontend()->setInitialSorting()) to synchronize backend logic with frontend configurations (e.g., DataTables.js settings). Reduces misalignment between UI and API responses.$ssp->setQuery(fn($cols) => User::select($cols))), enabling complex joins, subqueries, or conditional logic without hardcoding.DB::raw() changes).COUNT(*), LIMIT/OFFSET). For large datasets, ensure:
$ssp->response()->json($cache_timeout)) is leveraged.$formatter = fn($value, $model) => ...) can obscure query logic if overused. Risk of N+1 query issues if formatters trigger additional model loads.setFrontEndFramework()). Plan for migration effort if adopting mid-project.ORDER BY, WHERE, or search?DB::raw())?| Component | Compatibility | Mitigation |
|---|---|---|
| Laravel Version | 10.x–13.x (as of v3.11.0) | Pin version in composer.json; monitor Laravel 14 support. |
| PHP Version | 8.0+ | Use platform-check in CI to enforce minimum PHP version. |
| Database | MySQL, PostgreSQL, SQLite (via Eloquent) | Test with primary database first. |
| Frontend Libraries | DataTables.js (primary), others via SSP protocol | Use adapter pattern for non-DataTables frontends. |
| Caching Systems | Laravel cache (Redis, Memcached), file cache | Configure $cache_timeout based on data volatility. |
| Authentication | Laravel’s built-in auth (e.g., middleware, gates) | Apply existing auth middleware to SSP routes. |
composer require syamsoul/laravel-datatable-ssp.App\Traits\UsesDataTableSSP).use SoulDoit\DataTable\SSP;
class BaseController extends Controller {
protected function configureSSP(SSP $ssp): void {
$ssp->enableSearch()
->allowExportAllItemsInCsv()
->frontend()->setFramework('datatablejs');
}
}
$ssp->setQuery() with closures.$ssp->setQuery(function ($cols) {
return User::where('active', true)
->when($this->request->filled('role'), fn($q) => $q->where('role', $this->request->role))
->select($cols);
});
$('#table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ route("users.ssp") }}',
columns: [
{ data: 'id', name: 'id' },
{ data: 'email', name: 'email' }
]
});
itemsPerPage: -1).How can I help you explore Laravel packages today?