有条件地应用属性
您还可以指定响应中的某些属性只在满足特定测试时应用,如示例13-27所示。
public function toArray($request) {
return [
'name' => $this->name,
'breed' => $this->breed,
'rating' => $this->when(Auth::user()->canSeeRatings(), 12),
];
}
Last updated
Was this helpful?