-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor filters to some traits enable checking for implemented trait…
… and asking column and operator configuration.
- Loading branch information
Showing
4 changed files
with
97 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
|
||
namespace LaravelJsonApi\Eloquent\Filters\Concerns; | ||
|
||
|
||
trait HasColumn { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $column; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function column(): string | ||
{ | ||
return $this->column; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
|
||
namespace LaravelJsonApi\Eloquent\Filters\Concerns; | ||
|
||
trait HasOperator { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $operator; | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function eq(): self | ||
{ | ||
return $this->using('='); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function gt(): self | ||
{ | ||
return $this->using('>'); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function gte(): self | ||
{ | ||
return $this->using('>='); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function lt(): self | ||
{ | ||
return $this->using('<'); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function lte(): self | ||
{ | ||
return $this->using('<='); | ||
} | ||
|
||
/** | ||
* Use the provided operator for the filter. | ||
* | ||
* @param string $operator | ||
* @return $this | ||
*/ | ||
public function using(string $operator): self | ||
{ | ||
$this->operator = $operator; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function operator(): string | ||
{ | ||
return $this->operator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters