You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$activities = QueryBuilder::for(Activity::class)
->defaultSort('title')
->allowedFilters($this->filters)
->allowedIncludes($this->includes)
->allowedSorts($this->sorts);
if ($activity) {
$activities->where('id', $activity->id);
}
if ($user) {
$activities->whereHas('teams.users', function ($query) use ($user) {
$query->where('users.id', $user->id);
});
}
if ($community) {
$activities->where('community_id', $community->id);
}
return $activities;
}`
My Search controller looks like this:
`public function index(): SearchResource {
$communityService = new CommunityService;
$communities = $communityService->get();
$communities->where('status', CommunityStatus::ACTIVE->value);
Is there a way I can use the "includes" so that I target Communities or Activities? For example Communities has an accepted include named access but Activity doesn't. Am I able to include access and return it with the Community and not have it through an Error since Activity is also trying to access it?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
So I have an API "Search" that returns an array of "Communities" & "Activities".
Each one of them has it's own resource, query builder in their respective service classes:
Community:
`
public function get(Community $community = null): QueryBuilder {
$this->filters[] = AllowedFilter::partial('search', 'name');
$this->filters[] = AllowedFilter::custom('access', new CommunityAccessFilter);
$this->filters[] = AllowedFilter::custom('games', new CommunityGamesFilter);
$this->filters[] = AllowedFilter::custom('user', new CommunityUserFilter);
`
Activity:
`public function get(Activity $activity = null, User $user = null, Community $community = null): QueryBuilder {
$this->filters[] = AllowedFilter::partial('search', 'title');
$this->filters[] = AllowedFilter::exact('entryFee', 'entryFee.type');
$this->filters[] = AllowedFilter::exact('community_id');
$this->filters[] = AllowedFilter::exact('location', 'location.location_type');
$this->filters[] = AllowedFilter::exact('game_id');
$this->filters[] = AllowedFilter::partial('game_title', 'game.title');
$this->filters[] = AllowedFilter::exact('status');
My Search controller looks like this:
`public function index(): SearchResource {
$communityService = new CommunityService;
$communities = $communityService->get();
$communities->where('status', CommunityStatus::ACTIVE->value);
Is there a way I can use the "includes" so that I target Communities or Activities? For example Communities has an accepted include named
access
but Activity doesn't. Am I able to include access and return it with the Community and not have it through an Error since Activity is also trying to access it?Beta Was this translation helpful? Give feedback.
All reactions