1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Ship\Parents\Requests; |
4
|
|
|
|
5
|
|
|
use App\Containers\Authorization\Traits\AuthorizationTrait; |
6
|
|
|
use App\Ship\Engine\Traits\HashIdTrait; |
7
|
|
|
use App\Ship\Features\Exceptions\ValidationFailedException; |
8
|
|
|
use Illuminate\Contracts\Validation\Validator; |
9
|
|
|
use Illuminate\Foundation\Http\FormRequest as LaravelFormRequest; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Request |
13
|
|
|
* |
14
|
|
|
* A.K.A (app/Http/Requests/Request.php) |
15
|
|
|
* |
16
|
|
|
* @author Mahmoud Zalt <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
abstract class Request extends LaravelFormRequest |
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
use HashIdTrait; |
22
|
|
|
use AuthorizationTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Overriding this function to modify the any user input before |
26
|
|
|
* applying the validation rules. |
27
|
|
|
* |
28
|
|
|
* @return array |
29
|
|
|
*/ |
30
|
|
|
public function all() |
31
|
|
|
{ |
32
|
|
|
$requestData = parent::all(); |
33
|
|
|
|
34
|
|
|
$requestData = $this->applyValidationRulesToUrlParams($requestData); |
35
|
|
|
|
36
|
|
|
$requestData = $this->decodeHashedIdsBeforeApplyingValidationRules($requestData); |
37
|
|
|
|
38
|
|
|
return $requestData; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* apply validation rules to the ID's in the URL, since Laravel |
43
|
|
|
* doesn't validate them by default! |
44
|
|
|
* |
45
|
|
|
* Now you can use validation riles like this: `'id' => 'required|integer|exists:items,id'` |
46
|
|
|
* |
47
|
|
|
* @param array $requestData |
48
|
|
|
* |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
private function applyValidationRulesToUrlParams(Array $requestData) |
52
|
|
|
{ |
53
|
|
|
if (isset($this->urlParameters) && !empty($this->urlParameters)) { |
|
|
|
|
54
|
|
|
foreach ($this->urlParameters as $param) { |
|
|
|
|
55
|
|
|
$requestData[$param] = $this->route($param); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $requestData; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Overriding this function to throw a custom |
64
|
|
|
* exception instead of the default Laravel exception. |
65
|
|
|
* |
66
|
|
|
* @param \Illuminate\Contracts\Validation\Validator $validator |
67
|
|
|
* |
68
|
|
|
* @return mixed|void |
69
|
|
|
*/ |
70
|
|
|
public function failedValidation(Validator $validator) |
71
|
|
|
{ |
72
|
|
|
throw new ValidationFailedException($validator->getMessageBag()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.