Any way to modify charts to only return a subset of data?
I'm attempting to create a user activity chart and presently have users organized into smaller sub-sets. I wondered if there was a way to only show chart results for users within the same user's sub-set list? For example
I'm wondering if there is a way to use the
$activity
variable somehow instead of the class? Or can I filter it after the values are returned from getPerMonth?
Thanks in advance!12 Replies
Bump
You should be able to use
Trend::query()
instead of the model class.Thank you for responding! Attempted a few different variations with Trend::query(), but seem to get one of two errors.
For the first query, which attempts to place $activity into the query
The error is (ignore the line number, I have each attempt commented/uncommented on different lines):
and when my query is:
The error returns as:
It doesn’t work because it needs a Builder instance (before you call
::get()
.
BTW you code loads all activities and filters them in PHP instead of on a DB level.I wanted to understand what was possible programmatically
If you were to simplify it on a DB level, how would you? Using a DB:: call?
What are you trying to simplify? Can't you just apply a where condition?
You will have to forgive me, I only recently picked up and fell in love with laravel/filament so my understanding comes from my years of PHP knowhow and from other languages I know. I guess the issue is that I'm trying to learn the type of data that should be returned in order to structure the query correctly.
What I'm trying to do is to filter the Trend::model(UserActivity::class) to only output when a certain field in that class matches, eg: where('organizations_id', auth()->user()->organizations_id). The where condition seems to return the errors as shown above, whether called directly or as a variable passed in. Is it possible to utilize something like Trend(DB::table('user_activity')->where('value', $value)->get())?
Solution
You just used the get() in the wrong order.
I think you shouldn't have a get at all. It expects a Builder
Possibly, I’m just quoting my understanding from the packages readme.
But yea with a Builder the get() is implied.
So, you’re right.
Solved, thank you very much!