M3TAGH0ST
M3TAGH0ST
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
if I remember correctly I believe so, but I will do a quick check tomorrow morning and let you know 🙂
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
What I believe the issue would is that I'm managing to do my operator to apply the having on the base query 😄 which I'm stuck and got no clue on how to do it from that position :))
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
The default NumberConstraint::class constraint is using where basically I would just create an identical class and instead of where would be having but didn't work as smooth as I thought 😄
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
for a normal "filter" if I remember correctly I did like ->baseQuery(... return $query->having()) and it worked without any issue. 😄
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
It's getting triggered correctly when I want to apply the rule but the $query if I dump it there would look like this
SELECT * FROM table_name WHERE date >= '2025-01-15' AND date <= '2025-01-16' having sum_of_total_amount > 15
SELECT * FROM table_name WHERE date >= '2025-01-15' AND date <= '2025-01-16' having sum_of_total_amount > 15
Where my final base table query would look like this if I look in the debug bar
SELECT
SUM(amount) as sum_of_total_amount
FROM database.table_name
WHERE
date >= '2025-01-15' AND date <= '2025-01-16'
SELECT
SUM(amount) as sum_of_total_amount
FROM database.table_name
WHERE
date >= '2025-01-15' AND date <= '2025-01-16'
I think I skipped an outer select from the second cannot remmeber from the memory, but basically what is passed to the apply method from the operator is not the same query, I'm not even sure from where that query comes since it doesn't contain the aggregated columns,
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
Using Tables\Filters\Filter::make to create a minimum and max fields in the form and apply there using baseQuery() applies correctly having on the final query, but I have like 8 columns in the table that I need to have a minimum amount and maximum amount, and the feature provided by the constraints on query builder where you can add rules to it, it's exactly what I would need.
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
well I didn't add the inverse logic in it, since it's a rough version and I couldn't make it work I just set by default >
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
I think i must mention that last week I started working with filament so i'm kinda new to the game.. not really sure if I could call it a filter, seems more like a constraint for me that create dynamic rules to be applied
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
and. the custom HavingMinOperator
<?php

namespace App\Filament\App\QueryBuilder\Constraints\Operators;

class HavingMinOperator extends Operator
{
public function getName(): string
{
return 'havingMin';
}

public function getLabel(): string
{
// For demonstration, a simple label:
return 'Greater Than';
}

public function getSummary(): string
{
return 'Having Min: ' . Number::format($this->getSettings()['number']);
}

public function getFormSchema(): array
{
return [
TextInput::make('number')
->label('Min Value')
->numeric()
->required(),
];
}

public function apply(Builder $query, string $qualifiedColumn): Builder
{
$value = $this->getSettings()['number'] ?? null;

if (is_numeric($value)) {
// Because this is an aggregator, we do HAVING:
$query->having($qualifiedColumn, '>', $value);
}

dump($query->toRawSql()); // For debugging: remove later
return $query;
}
}
<?php

namespace App\Filament\App\QueryBuilder\Constraints\Operators;

class HavingMinOperator extends Operator
{
public function getName(): string
{
return 'havingMin';
}

public function getLabel(): string
{
// For demonstration, a simple label:
return 'Greater Than';
}

public function getSummary(): string
{
return 'Having Min: ' . Number::format($this->getSettings()['number']);
}

public function getFormSchema(): array
{
return [
TextInput::make('number')
->label('Min Value')
->numeric()
->required(),
];
}

public function apply(Builder $query, string $qualifiedColumn): Builder
{
$value = $this->getSettings()['number'] ?? null;

if (is_numeric($value)) {
// Because this is an aggregator, we do HAVING:
$query->having($qualifiedColumn, '>', $value);
}

dump($query->toRawSql()); // For debugging: remove later
return $query;
}
}
23 replies
FFilament
Created by M3TAGH0ST on 1/29/2025 in #❓┊help
Table Query Builder with Constraints
I don't have currently access to the code, tomorrow morning I could share a snippet, what part are you interested in seeing ?
23 replies