diff --git a/app/Filters/ProductFilters.php b/app/Filters/ProductFilters.php index 77d8d3959446..a406b6521f19 100644 --- a/app/Filters/ProductFilters.php +++ b/app/Filters/ProductFilters.php @@ -19,6 +19,8 @@ use Illuminate\Database\Eloquent\Builder; */ class ProductFilters extends QueryFilters { + protected $with_property = 'product_key'; + /** * Filter based on search text. * diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index 370ae558e09e..83fb8a36fdc6 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -52,6 +52,13 @@ abstract class QueryFilters */ protected $builder; + /** + * The "with" filter property column. + * + * var string + */ + protected $with_property = 'id'; + /** * Create a new QueryFilters instance. * @@ -218,4 +225,11 @@ abstract class QueryFilters return $this->builder; } + + public function with(string $value): Builder + { + return $this->builder + ->orWhere($this->with_property, $value) + ->orderByRaw("{$this->with_property} = ? DESC", [$value]); + } }