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

Use filter to add accessor data to response #99

Closed
hrvoj3e opened this issue Mar 21, 2022 · 1 comment
Closed

Use filter to add accessor data to response #99

hrvoj3e opened this issue Mar 21, 2022 · 1 comment
Assignees

Comments

@hrvoj3e
Copy link

hrvoj3e commented Mar 21, 2022

Hi.

First, let me say - great idea with filters. Looks nice.

How would you go about show/hide accessor data or some other custom data derivative?

Lets use simple User example.

// accessor
public function getFullNameAttribute()	 	 
{	 	 
    return $this->first_name . ' ' . $this->last_name;	 	 
}

public function getAgeAttribute()
{
   return Carbon::parse($this->attributes['birthday'])->age;
}

I would like to allow user to toggle some fields that are not stored in model

/users?with=full_name,age

I have implemented a solution based on JsonResource and with custom mergeWhen logic but I would like to hear your input with EloquentBuilder.

I know about appends - but I do not want to always include that data in all responses.

protected $appends = ['age'];
@50bhan
Copy link
Collaborator

50bhan commented Mar 24, 2022

@hrvoj3e I believe you're talking about how to present your data (using accessors) and this is out of the scope of this package.

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

No branches or pull requests

3 participants