Replies: 1 comment
-
I do not think it is possible to use the query builder for data, that is not persisted in your database. In my mind, a straight forward way would be to use Laravel Collection methods to filter the result received by the $models = QueryBuilder()->get();
// Careful! Includes get CamelCased in the "getter"
if (app(QueryBuilderRequest::class)->includes()->contains('Foo')) {
$models = $models->filter(fn($m) => $m->isSubscribedBy(Auth::user());
}
// Or alternatively without an if block
$shouldFilterByFoo = app(QueryBuilderRequest::class)->includes()->contains('Foo');
$models = $models->filter(fn($m) => $shouldFilterByFoo && $m->isSubscribedBy(Auth::user()); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hi,
I've looking for help on filtering my models by a model method but can't seem to get my head around this scenario ...
I'd like to filter models by some values that aren't in the models own table but are values returned by related methods.
my Board model uses
Overtrue\LaravelSubscribe\Traits\Subscribable
which is a subscriber relationship that can be used like:Auth::User()->hasSubscribed($model)
or$model->isSubscribedBy(Auth::user())
my questions is, how would/could i filter my $model using this method?
I have tried creating a test model method
then using it in my controllers as such:
but only receive errors like:
Column not found: 1054 Unknown column 'foo'
can I ask how to filter models like this?
Beta Was this translation helpful? Give feedback.
All reactions