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.
Below are five raw SQL with MySQL syntax examples, along with the location where you can find them so you can explore more.
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()
usageif()
usagecase ... when ...
usagedate_format()
usageconcat()
usageAll examples will include real use-case in the code. From tables to dashboard widgets.