From 2ded76aa2e131414b91fccd161037cf617edb529 Mon Sep 17 00:00:00 2001 From: Tan Nguyen Date: Sat, 7 Dec 2024 23:24:57 +0700 Subject: [PATCH] fix: optimize role name for author data --- src/Http/Resources/AuthorResource.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Http/Resources/AuthorResource.php b/src/Http/Resources/AuthorResource.php index f76764f..729eae7 100644 --- a/src/Http/Resources/AuthorResource.php +++ b/src/Http/Resources/AuthorResource.php @@ -16,14 +16,12 @@ public function toArray($request): array { /** @var User $this */ - $role = $this->roles->first()->name ?? null; - return [ 'id' => $this->id, 'first_name' => $this->first_name, 'last_name' => $this->last_name, 'image' => $this->avatar_url, - 'role' => $role, + 'role' => $this->roles?->first()?->name ?? null, ]; } }