Files
lucent-laravel/src/Query/BuilderConverter/LessThan.php
T

35 lines
839 B
PHP
Raw Normal View History

2024-08-24 17:22:40 +03:00
<?php
namespace Lucent\Query\BuilderConverter;
use Illuminate\Database\Query\Builder;
use Lucent\Query\Filter\Argument;
readonly class LessThan implements IBuilderConverter
{
public function __construct(private Argument $argument)
{
}
public function toAndQueryBuilder(Builder $builder): Builder
{
return $builder->where($this->argument->field, "<", $this->formatValue());
}
public function toOrQueryBuilder(Builder $builder): Builder
{
return $builder->orWhere($this->argument->field, "<", $this->formatValue());
}
2025-06-16 18:23:14 +03:00
private function formatValue(): int|float|string
2024-08-24 17:22:40 +03:00
{
$value = trim($this->argument->value);
if (is_numeric($value)) {
return str_contains($value, ".") ? floatval($value) : intval($value);
}
return $value;
}
}