1. Go to this page and download the library: Download laravelldone/sql-to-signal 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/ */
class OrderDashboard extends Component
{
// You can't store a QueryBuilder as a public property.
// Livewire can't serialize it — it will throw or silently drop it.
// So you have to rebuild the query from scratch on every request.
public array $orders = []; // you lose Collection methods
public int $count = 0;
public ?array $first = null;
private function baseQuery(): Builder
{
// Duplicated every time: if filters change you must update in multiple places
return DB::table('orders')
->where('status', $this->status)
->where('user_id', auth()->id())
->orderBy('created_at', 'desc');
}
public function mount(): void
{
$q = $this->baseQuery();
$this->orders = $q->get()->toArray(); // hit 1
$this->count = (clone $q)->count(); // hit 2 ← extra query
$this->first = (clone $q)->first(); // hit 3 ← extra query
}
public function refresh(): void
{
// Rebuild everything again — same 3 queries
$q = $this->baseQuery();
$this->orders = $q->get()->toArray();
$this->count = (clone $q)->count();
$this->first = (clone $q)->first();
}
}
class OrderDashboard extends Component
{
public Signal $orders; // serializes/hydrates automatically between requests
public function mount(): void
{
// One query, one database hit. count/first/pluck come for free.
$this->orders = DB::table('orders')
->where('status', $this->status)
->where('user_id', auth()->id())
->orderBy('created_at', 'desc')
->toSignal();
}
public function refresh(): void
{
// Re-runs the exact same SQL — no need to rebuild the query
$this->orders = $this->orders->refresh();
}
}
use Livewire\Component;
use Laravelldone\SqlToSignal\Signal;
class OrderDashboard extends Component
{
public Signal $orders;
public function mount(): void
{
$this->orders = Order::pending()->toSignal();
}
public function refresh(): void
{
$this->orders = $this->orders->refresh();
// Re-runs the original SQL with the same bindings.
// No need to rebuild the query from scratch.
}
public function render()
{
return view('livewire.order-dashboard');
}
}
public function mount(): void
{
$this->orders = Order::pending()
->orderBy('created_at', 'desc')
->toSignal(['per_page' => 15, 'page' => 1]);
}
public function nextPage(): void { $this->orders = $this->orders->nextPage(); }
public function prevPage(): void { $this->orders = $this->orders->prevPage(); }
public function goToPage(int $page): void { $this->orders = $this->orders->goToPage($page); }
// Table has 1 500 rows — this throws immediately
$signal = Report::query()->toSignal(['max_rows' => 500]);
// OverflowException: Signal result set exceeds the configured max_rows limit
// of 500. Got 1500 rows.
// Safe — scoped
$signal = Report::thisMonth()->toSignal(['max_rows' => 500]);
// Unlimited — use with care
$signal = Report::query()->toSignal(['max_rows' => null]);