forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path011.php
More file actions
29 lines (24 loc) · 634 Bytes
/
011.php
File metadata and controls
29 lines (24 loc) · 634 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
namespace App\Transformers;
use CodeIgniter\API\BaseTransformer;
class BookTransformer extends BaseTransformer
{
public function toArray(mixed $resource): array
{
return [
'id' => $resource['id'],
'title' => $resource['title'],
'year' => $resource['year'],
];
}
protected function includeAuthor(array $book): ?array
{
if (empty($book['author_id']) || empty($book['author_name'])) {
return null;
}
return [
'id' => $book['author_id'],
'name' => $book['author_name'],
];
}
}