Skip to content

Commit

Permalink
Merge branch 'when-pivot-loaded-as' of https://github.com/staudenmeir…
Browse files Browse the repository at this point in the history
…/docs into staudenmeir-when-pivot-loaded-as
  • Loading branch information
taylorotwell committed Sep 19, 2018
2 parents d65d9f3 + c8c1fbd commit c2ac9fa
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 c2ac9fa

Please sign in to comment.