Filament: Raw SQL Usage in Tables and Widgets

Filament 4/5
Also available in Filament 3 version

Five examples of raw SQL usage with MySQL database.

01JE3BT9B01JHCQ8CXM5HW5F42

Get the Source Code:

Only This Example

$9

One-time payment

Full source code for Filament: Raw SQL Usage in Tables and Widgets
Downloadable ZIP file with the source code
Lifetime access to this example
GitHub Sign in with GitHub to buy

Sign in first, then complete your $9 checkout.

Best value — all 169 examples

FilamentExamples Membership

$99 /year
or
$199 lifetime
Access to code of all 169 examples
Future new examples and updates included
FilaCheck Pro package licence included
MCP server included
View membership plans

30-day money-back guarantee

How it works

Below are five raw SQL with MySQL syntax examples, along with the location where you can find them so you can explore more.

1. AVG() with ROUND()

app/Filament/Resources/MetricResource.php:

return $table
->modifyQueryUsing(function (Builder $query) {
$query->select(
[
'id',
'server_id',
DB::raw('created_at as date'),
DB::raw('ROUND(AVG(`load`), 2) as `load`'),
DB::raw('ROUND(AVG(memory_total), 2) as memory_total'),
DB::raw('ROUND(AVG(memory_used), 2) as memory_used'),
DB::raw('ROUND(AVG(memory_free), 2) as memory_free'),
DB::raw('ROUND(AVG(disk_total), 2) as disk_total'),
DB::raw('ROUND(AVG(disk_used), 2) as disk_used'),
DB::raw('ROUND(AVG(disk_free), 2) as disk_free'),
],
)
->groupByRaw('server_id');
The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.