|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SaasReady\Http\Requests\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Validation\ValidationException; |
|
|
|
|
|
|
7
|
|
|
use SaasReady\Http\Requests\BaseFormRequest; |
|
8
|
|
|
|
|
9
|
|
|
class EventIndexRequest extends BaseFormRequest |
|
10
|
|
|
{ |
|
11
|
|
|
private ?Model $source = null; |
|
12
|
|
|
|
|
13
|
|
|
protected function getEndpointName(): string |
|
14
|
|
|
{ |
|
15
|
|
|
return 'events.index'; |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function rules(): array |
|
19
|
|
|
{ |
|
20
|
|
|
return [ |
|
21
|
|
|
'limit' => 'required|int|max:100', |
|
22
|
|
|
'page' => 'required|int|min:1', |
|
23
|
|
|
'source_type' => 'required|string', |
|
24
|
|
|
'source_id' => 'required|int', |
|
25
|
|
|
'user_id' => 'nullable|int', |
|
26
|
|
|
'load_related_model' => 'nullable|bool', |
|
27
|
|
|
]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function passedValidation() |
|
31
|
|
|
{ |
|
32
|
|
|
if (!class_exists($this->input('source_type'))) { |
|
33
|
|
|
throw ValidationException::withMessages([ |
|
34
|
|
|
'source_type' => 'Source Type is not a valid Eloquent Class', |
|
35
|
|
|
]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if (!$this->getRelatedModel()) { |
|
39
|
|
|
throw ValidationException::withMessages([ |
|
40
|
|
|
'source_id' => 'Source is invalid', |
|
41
|
|
|
]); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getLimit(): int |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->input('limit') ?: 10; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getUserId(): int |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->integer('user_id'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function getRelatedModel(): ?Model |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->source |
|
58
|
|
|
??= $this->input('source_type')::find($this->input('source_id')); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths