ActivityExpandRequest.php
2.5 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
namespace App\Http\Request;
use Hikoon\LaravelApi\Support\ApiRequest;
use Illuminate\Support\ValidatedInput;
class ActivityExpandRequest extends ApiRequest
{
protected function getExpand(): array
{
$expand = $this->input('expand', []);
return [
'push_type' => ['tag'],
'push_user' => [],
'tag_ids' => data_get($expand, 'tag_ids', []),
'lyricist' => [
'ids' => data_get($expand, 'lyricist.ids', []),
'supplement' => data_get($expand, 'lyricist.supplement', []),
],
'composer' => [
'ids' => data_get($expand, 'composer.ids', []),
'supplement' => data_get($expand, 'composer.supplement', []),
],
'arranger' => [
'ids' => data_get($expand, 'arranger.ids', []),
'supplement' => data_get($expand, 'arranger.supplement', []),
],
'track_source' => [
'url' => data_get($expand, 'track_source.url', ''),
'name' => data_get($expand, 'track_source.name', ''),
'size' => data_get($expand, 'track_source.size', 0),
],
'guide_source' => [
'url' => data_get($expand, 'guide_source.url', ''),
'name' => data_get($expand, 'guide_source.name', ''),
'size' => data_get($expand, 'guide_source.size', 0),
],
'karaoke_source' => [
'url' => data_get($expand, 'karaoke_source.url', ''),
'name' => data_get($expand, 'karaoke_source.name', ''),
'size' => data_get($expand, 'karaoke_source.size', 0),
],
];
}
/**
* @inheritDoc
*/
protected function prepareForValidation(): void
{
$this->merge(['expand' => $this->getExpand()]);
}
/**
* @inheritDoc
*/
public function validated($key = NULL, $default = NULL)
{
return array_merge(parent::validated($key, $default), ['expand' => $this->getExpand()]);
}
/**
* @param array|NULL $keys
* @return array|array[]|\Illuminate\Support\ValidatedInput
*/
public function safe(array $keys = NULL): array|ValidatedInput
{
return is_array($keys)
? $this->validator->safe()->only($keys) + ['expand' => $this->getExpand()]
: $this->validator->safe()->merge(['expand' => $this->getExpand()]);
}
}