Skip to content

Commit

Permalink
Add whenPivotLoadedAs()
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Sep 18, 2018
1 parent bf9b804 commit c8c1fbd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions eloquent-resources.md
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,25 @@ In addition to conditionally including relationship information in your resource
];
}

Use `whenPivotLoadedAs` for relationships with a custom accessor:

/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'expires_at' => $this->whenPivotLoadedAs('accessor', 'role_user', function () {
return $this->accessor->expires_at;
}),
];
}

<a name="adding-meta-data"></a>
### Adding Meta Data

Expand Down

0 comments on commit c8c1fbd

Please sign in to comment.