Releases: KalimeroMK/filterable
Refactor
Simplified Condition Logic: Replaced the when() method with a simple if-else condition. This makes the logic more straightforward and easier to read.
Return Statement: Ensured that the macro method explicitly returns $this to maintain the fluid interface of the query builder.
Removed Redundant Closure: The second closure passed to when() in the original code was not necessary because the alternative case can be handled directly in the else block of the if-else statement.
Optimize the code fix psr-4 standard
- The logic for applying field filters has been moved to a separate method, applyFieldFilter(). This helps in improving readability and separation of concerns.
- By extracting the field filtering logic into its own method, the main scopeFilter() method becomes more focused and easier to understand.
- The $query parameter is now passed as a reference to the applyFieldFilter() method to allow direct modification of the query builder instance.
- The is_numeric($value) condition check for like fields has been removed, as it seems unnecessary.
- The trait's methods and properties are assumed to be used in a model class that extends Illuminate\Database\Eloquent\Model. Make sure to import the necessary classes and define the properties such as boolFields and likeFields within the model class that uses this trait.
v1.4
Remove publish method for traits
v1.3
Code refactor PSR12
Refactored version of the code
Changes made:
The parameter type and name of the method have been updated to match Laravel's conventions for scope methods.
$this->fillable has been changed to $this->getFillable() to make sure it always returns the correct value, even if the fillable property is modified later on.
The conditions inside the loop have been simplified to avoid unnecessary continue statements and duplicate checks.
The method now returns the modified query builder instance instead of always returning the input query builder.
Code reformat to PSR12
Add whereLike macro
Add whereLike macro in boot method to searche useing where like try database rows and relations
Stable
In Laravel, we commonly face the problem of adding repetitive filtering code, this package will address this problem