Passed
Pull Request — main (#62)
by Tan
03:01
created

AuthorWithPostResource   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 12 1
1
<?php
2
3
namespace CSlant\Blog\Api\Http\Resources\Author;
4
5
use CSlant\Blog\Core\Models\User;
6
use Illuminate\Http\Resources\Json\JsonResource;
7
8
/**
9
 * @mixin User
10
 */
11
class AuthorWithPostResource extends JsonResource
12
{
13
    /**
14
     * @param $request
15
     *
16
     * @return array<string, mixed>
17
     */
18
    public function toArray($request): array
19
    {
20
        /** @var User $this */
21
22
        return [
23
            'id' => $this->id,
24
            'email' => $this->email,
25
            'first_name' => $this->first_name,
26
            'last_name' => $this->last_name,
27
            'username' => $this->username,
28
            'image' => $this->avatar_url,
29
            'posts' => $this->posts()->orderBy($request->order_by, $request->order)->paginate($request->per_page ?? 10),
30
        ];
31
    }
32
}
33