Skip to content

Commit

Permalink
User Resource inherits from BasResource and hide fields
Browse files Browse the repository at this point in the history
  • Loading branch information
tavobarrientos committed Jan 3, 2019
1 parent 9a39fae commit 7d4feb2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function store(Request $request)
*/
public function show($id)
{
return new UserResource(User::find($id));
return UserResource::make(User::find($id))->hide(['meta']);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Resources/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Http\Resources\Json\JsonResource;

class User extends JsonResource
class User extends BaseResource
{
/**
* Transform the resource into an array.
Expand All @@ -15,7 +15,7 @@ class User extends JsonResource
public function toArray($request)
{
try {
return [
return parent::filterFields([
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
Expand All @@ -24,7 +24,7 @@ public function toArray($request)
'rel' => 'self',
'link' => route('users.show', $this->id)
]
];
]);
} catch (\Throwable $th) {
return [
'hasError' => true,
Expand Down

0 comments on commit 7d4feb2

Please sign in to comment.