Filament: Raw SQL Usage in Tables and Widgets

Filament 3
Also available in Filament 4/5 version

While most data can be accessed via a simple select query, Raw SQL is sometimes required. For example, if we want to take averages of multiple columns.

FilamentExamples ThumbBase - 2024-12-02T113220.812

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'),
// ...

Example queries in this project:

  • avg() and round() usage
  • if() usage
  • case ... when ... usage
  • date_format() usage
  • concat() usage

All examples will include real use-case in the code. From tables to dashboard widgets.

The FULL tutorial is available after the purchase: in the Readme file of the official repository you would get invited to.