Skip to content
This repository was archived by the owner on Nov 4, 2021. It is now read-only.

Commit f542a0a

Browse files
authored
Merge pull request #29 from douglasgalico/master
Adding "when" and FilterBuilder and fix unexpected semicolon
2 parents fcc5857 + ab1ef44 commit f542a0a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/Builders/FilterBuilder.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function where($field, $value)
4444
$this->wheres['must'][] = ['range' => [$field => ['gt' => $value]]];
4545
break;
4646

47-
case '<';
47+
case '<':
4848
$this->wheres['must'][] = ['range' => [$field => ['lt' => $value]]];
4949
break;
5050

@@ -114,6 +114,17 @@ public function whereRegexp($field, $value, $flags = 'ALL')
114114
return $this;
115115
}
116116

117+
public function when($value, callable $callback, callable $default = null)
118+
{
119+
if ($value) {
120+
return $callback($this);
121+
} elseif ($default) {
122+
return $default($this);
123+
}
124+
125+
return $this;
126+
}
127+
117128
public function orderBy($column, $direction = 'asc')
118129
{
119130
$this->orders[] = [$column => strtolower($direction) == 'asc' ? 'asc' : 'desc'];
@@ -142,4 +153,4 @@ public function with($relations)
142153

143154
return $this;
144155
}
145-
}
156+
}

src/Builders/SearchBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ public function rule($rule)
1919

2020
return $this;
2121
}
22-
}
22+
}

0 commit comments

Comments
 (0)