Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Datatables Bundle With Regex Laravel Package

victorbalssa/datatables-bundle-with-regex

A Symfony DataTables bundle with regex-enabled filtering for advanced server-side search. It extends standard DataTables query controls so you can match complex patterns and build more flexible data grids.

View on GitHub
Deep Wiki
Context7

Getting Started

This is a fork/wrapper of the DataTables server-side bundle with added regex filtering support, shipped at 0.8.x — pre-1.0, so treat the API as unstable.

  1. Install and register. composer require victorbalssa/datatables-bundle-with-regex:0.8.1 (pin the patch, see Gotchas). If your Laravel version doesn't auto-discover the service provider, add it manually to config/app.php. Then publish the config:
    php artisan vendor:publish --tag=datatables
    php artisan config:clear
    
  2. Look first at the config file (adapter defaults, cache/metadata settings) and the bundle's DataTable base class — that class is the extension point you'll subclass once per table. Check the adapter namespace too: whether you get an ORM/Doctrine adapter, a query-builder adapter, or an array adapter determines everything downstream.
  3. First use case — a single server-side table over one model. php artisan make: isn't provided, so hand-write a class extending the base, declare your columns, then point it at a query source:
    class UsersTable extends AbstractDataTable
    {
        public function build(): static
        {
            return $this->add('id', 'u.id')
                ->add('name', 'u.name')
                ->add('email', 'u.email')
                ->createAdapter(/* ORM or QueryBuilder source */);
        }
    }
    
  4. Wire an endpoint and a view. A thin controller returns $table->handleRequest() (JSON for DataTables' ajax), a route points at it, and the Blade view renders the <table> plus the standard $('#users').DataTable({ serverSide: true, processing: true, ajax: '...' }) init. Put the route behind auth middleware from the very first commit — an unguarded DataTables endpoint is a full table dump.

The fastest sanity check is a two-column table over a table with <100 rows: if recordsTotal looks right and sorting toggles, your adapter and column-to-DB mapping are correct, and everything else is incremental.

Implementation Patterns

One DataTable class per resource, kept thin. Configure columns and the adapter in the class; keep request-derived filtering (tenant id, date range, "my records only") in a service or via container injection so the table stays testable. Injecting the authenticated user or a filter DTO into build() is the cleanest way to scope rows without touching the controller.

Column declaration drives everything. Each add() maps a front-end data key to a DB column/alias. Set searchable/sortable flags explicitly rather than relying on defaults — it prevents accidental full-table LIKE scans on wide text columns and accidental ordering on unindexed columns.

Regex search is the differentiator, so use it deliberately. Two patterns work well:

  • Global regex off, per-column regex on. Enable regex: true only on the specific columns where users need pattern matching (SKUs, prefixed IDs, log codes) via columns[i].search.regex = true in JS, and mark only those columns searchable.
  • Server-side "smart filter" input. A separate Blade input that maps to a named column search with regex: true, giving users a documented mini-language rather than a raw regex box on every field.

Keep the regex column count small and the underlying columns indexed. A regex filter is a non-sargable predicate — it will seq-scan, so pair it with a mandatory date range or tenant scope.

Adapter choice is an architectural decision, not a detail. If the bundle's adapter is ORM/Doctrine-flavoured, wrapping Eloquent means converting to the query builder or using the raw/array adapter. Whichever you pick, do it once in a base class (App\Support\DataTables\BaseTable) so a future 0.9/1.0 adapter change is a one-file edit.

Formatters belong in the table, not the view. Use the column render/formatter hook to emit action buttons, statuses, and dates. Emit pre-escaped HTML or structured JSON consistently — half-escaped cells are the most common XSS vector in DataTables apps.

Testing. Hit the AJAX route in a feature test with DataTables' query params (draw, start, length, columns[...], search[value]) and assert on draw, recordsTotal, recordsFiltered, and the shape of a row. Add one test per adapter filter, and one specifically for a regex column — that's the code path this fork exists for.

Version discipline. Because this is a 0.8.x fork, treat the lockfile as load-bearing and add a composer outdated review step before bumping. Diff every release with git compare — as in 0.8.1, the release notes may be nothing but a compare link.

Gotchas and Tips

  • 0.8.1's release notes are only a changelog URL. There's no stated BC break, but there's also no stated anything. Diff 0.8.0...0.8.1 yourself before upgrading and pin "victorbalssa/datatables-bundle-with-regex": "0.8.1" rather than ^0.8 if you're in production. Pre-1.0 semver gives you nothing.
  • User-supplied regex is a denial-of-service surface. A pathological pattern (nested quantifiers) can pin a DB core. Cap search-string length at the controller/middleware level, rate-limit the endpoint, and never enable regex: true globally on all columns.
  • Regex dialect varies by database. MySQL REGEXP, PostgreSQL ~, and SQLite (no native regex) do not behave identically. If the package translates regex to LIKE for non-supporting adapters, your tests will pass on MySQL and silently degrade elsewhere. Verify on your actual driver.
  • Parameterisation. Confirm the adapter binds search values as parameters. If you extend the adapter, never concatenate the search string into SQL — this is the classic injection path in DataTables integrations.
  • recordsFiltered ≠ recordsTotal once you join. One-to-many joins duplicate rows and break counts. Use distinct on the primary key and verify both counts on a joined table before shipping.
  • Column aliases must match the JS data keys exactly, including join ambiguity (u.id vs id). Mismatched names fail silently — the column renders empty with no error in the console.
  • Non-searchable columns still need declaring if the front end needs to order by them; omitting them produces an "unknown parameter" ordering error.
  • Config caching bites on first install. After publishing the config, run php artisan config:clear; otherwise a stale cached config makes your adapter edits appear ignored.
  • Large offsets get slow. LIMIT/OFFSET degrades on deep pagination; if the bundle only offers offset paging, keep default page sizes small and push heavy consumers onto filtered queries via the regex/date filters rather than page 500.
  • Extension points worth knowing: a custom adapter (to bridge a non-supported source), a shared abstract base table (for global scoping, formatting, and metadata caching), and the handleRequest entry point if you need to wrap the JSON response in a policy check or audit log.
  • Debugging tip: log the incoming DataTables params and the final SQL together (Laravel's query log plus a Log::debug in the controller). Nearly every "wrong results" bug is either a column-mapping mismatch or a filter applied to the wrong column index.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager