Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How filter (gt) great than or (lt) less than? #15

Closed
yurirnascimento opened this issue Jun 12, 2018 · 3 comments
Closed

How filter (gt) great than or (lt) less than? #15

yurirnascimento opened this issue Jun 12, 2018 · 3 comments
Labels
enhancement New feature or request

Comments

@yurirnascimento
Copy link

yurirnascimento commented Jun 12, 2018

How filter (gt) great than or (lt) less than?

Like spatie/laravel-query-builder example.

$user = QueryBuilder::for($query)
    ->allowedIncludes('posts', 'permissions')
    ->where('score', '>', 42) **<< this**
    ->first();

Reading the code, this is not possible right now.

Updated:

Sure, we can create scoped filters, but, a lot of work for a Great/Less than only.

@robsontenorio
Copy link
Owner

Yes, indeed the same problem as #7. I will keep this open. If you have any solution, please submit a PR.

@robsontenorio robsontenorio added the enhancement New feature or request label Jul 22, 2018
@bpuig
Copy link

bpuig commented Feb 16, 2019

That example you are quoting is not a filter, but an example for an existing query.
I think there is no chained method for that, spatie's laravel-query-builder specifies that any extra filter has to be made into a scope or custom filter:
See Scope Filters section
See Custom Filters section

I have not tested, but this would have to work if your $query is a User model class element.
This is the scoped approach:
In your User model
Referenced Builder is this one: use Illuminate\Database\Eloquent\Builder;

public function scopeScoreGreaterThan(Builder $query, $value): Builder
   {
       return $query->where('score', '>',  $value);
   }

And then in your UserController

$user = QueryBuilder::for($query)
    ->allowedIncludes('posts', 'permissions')
    ->allowedFilters(Filter::scope('score_greater_than'))
    ->first();

@robsontenorio
Copy link
Owner

@bpuig thanks for explanation. As, mentioned in another issue, by now, there is no default way to handle it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants