Five examples of raw SQL usage with MySQL database.
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
Sign in with GitHub to buy
Sign in first, then complete your $9 checkout.
Best value — all 177 examples
View membership plans
FilamentExamples Membership
$99
/year
or
$199
lifetime
Access to code of all 177 examples
Future new examples and updates included
FilaCheck Pro package licence included
MCP server included
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.