Merge pull request #7692 from beganovich/with-filter-stable

`with` filter
This commit is contained in:
David Bomba 2022-07-28 18:20:21 +10:00 committed by GitHub
commit 066f959c7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -19,6 +19,8 @@ use Illuminate\Database\Eloquent\Builder;
*/
class ProductFilters extends QueryFilters
{
protected $with_property = 'product_key';
/**
* Filter based on search text.
*

View File

@ -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]);
}
}