Download the PHP package laravelldone/sql-to-signal without Composer
On this page you can find all versions of the php package laravelldone/sql-to-signal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package sql-to-signal
sql-to-signal
UNDER-DEVELOPMENT
Call ->toSignal() on any Eloquent or Query Builder chain and get back a reactive Signal object — ready to wire into Livewire 3/4 components and Alpine.js without any boilerplate.
Why not just clone $query?
The clone pattern is the typical workaround when you need to reuse a query builder — but it falls apart quickly in Livewire and Alpine.js contexts.
Reusing a query in a Livewire component
Without toSignal() — clone pattern
Problems:
cloneonly works within the same request — you can't put aBuilderin a Livewire property- The query definition is repeated or called through a private helper — easy to drift out of sync
- 3 separate database hits to get the same data
toArray()discards the model — you get raw stdClass, no Eloquent methods on rows
With toSignal()
Passing data to Alpine.js
Without toSignal()
Gotchas:
- Two database hits for the same filter
- You manually
json_encodeeach piece - Polling interval is a magic number hard to change in one place
- No single object you can pass to a sub-component or an API response
With toSignal()
Summary
clone $query |
->toSignal() |
|
|---|---|---|
| Survives Livewire serialization | No — Builder can't be a public property | Yes — Signal hydrates/dehydrates cleanly |
| Database hits for count + first | Extra query each | Zero — derived from the same Collection |
| Refresh in Livewire | Rebuild query from scratch | $signal->refresh() |
| Alpine.js wiring | Manual json_encode per variable |
@js($signal) — data + meta in one shot |
| Model hydration on refresh | Lost — raw stdClass |
Preserved — Eloquent models rebuilt |
| Polling interval in sync | Hard-coded in JS | Carried in signal.meta.polling_interval |
Requirements
- PHP 8.2+
- Laravel 11, 12, or 13
- Livewire 3 or 4
Installation
The service provider is auto-discovered. To publish the config file:
Configuration
config/sql-to-signal.php:
Basic Usage
Query Builder
Eloquent Builder
Override config per call
Using in Livewire
Declare a Signal as a public property — it serializes/hydrates automatically via the built-in Livewire synthesizer:
What Livewire sends over the wire (dehydrated payload):
For a paginated Signal, pagination_meta carries the full page state:
On the next request Livewire hydrates this back into a full Signal — no database hit until you call refresh().
Auto-polling with Livewire
Every 5 seconds Livewire calls refresh(), re-executes the query, and re-renders only the changed rows.
Using with Alpine.js
Signal implements JsonSerializable, so you can pass it directly to @js or an API endpoint:
@js($orders) renders:
Use signal.meta.polling_interval to drive a JS polling interval without hard-coding it:
Pagination
Unlike Livewire's built-in WithPagination (which only works inside render()), Signal pagination works anywhere — including mount().
Pagination meta is carried in toArray() and survives the Livewire wire round-trip:
Pass it to Alpine.js for client-side pagination controls without any extra wiring:
Pagination API
| Method | Return type | Description |
|---|---|---|
isPaginated() |
bool |
true when created with per_page |
getTotal() |
int |
Total rows across all pages |
getPerPage() |
int |
Rows per page |
getCurrentPage() |
int |
Current page number |
getLastPage() |
int |
Last page number |
nextPage() |
Signal |
Signal for the next page (clamped at last page) |
prevPage() |
Signal |
Signal for the previous page (clamped at page 1) |
goToPage(int $page) |
Signal |
Signal for an arbitrary page |
Signal API
| Method | Return type | Description |
|---|---|---|
getData() |
Collection |
Full result set for the current page |
getQuery() |
string |
Base SQL with ? placeholders (no LIMIT/OFFSET) |
getBindings() |
array |
Ordered binding values |
getModelClass() |
string\|null |
Eloquent model class, or null for raw queries |
getConnectionName() |
string\|null |
Database connection name |
refresh() |
Signal |
Re-runs the query; re-runs the same page if paginated |
count() |
int |
Row count for the current page |
isEmpty() |
bool |
true when the current page is empty |
first() |
mixed |
First row/model on the current page, or null |
pluck(key, value?) |
Collection |
Delegates to Collection::pluck() |
toArray() |
array |
['data' => [...], 'meta' => [...]] |
toLivewire() |
array |
Full serialized payload for Livewire transport |
Signal::fromLivewire($value) |
Signal |
Reconstructs a Signal from a Livewire payload |
Safety: max_rows
To prevent accidentally serializing large datasets through Livewire's JSON cycle, an OverflowException is thrown when the result count exceeds max_rows:
Scope your query before calling toSignal(), or set max_rows to null to disable the limit entirely:
License
MIT — see LICENSE.
All versions of sql-to-signal with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
livewire/livewire Version ^3.0|^4.0
spatie/laravel-package-tools Version ^1.9