Skip to content

Use filter to add accessor data to response #99

@hrvoj3e

Description

@hrvoj3e

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'];

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions