1
|
|
|
@php echo "<?php" |
|
|
|
|
2
|
|
|
@endphp |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
namespace App\Http\Requests\{{ $modelWithNamespaceFromDefault }}; |
6
|
|
|
@php |
7
|
|
|
$standardColumns = $columns->reject(function($column) use ($relatable) { |
8
|
|
|
return in_array($column['name'], $relatable->pluck('name')->toArray())|| $column["name"]=='slug'; |
9
|
|
|
}); |
10
|
|
|
$relatableColumns = $columns->filter(function($column) use ($relatable) { |
11
|
|
|
return in_array($column['name'], $relatable->pluck('name')->toArray()); |
12
|
|
|
})->keyBy('name'); |
13
|
|
|
@endphp |
14
|
|
|
|
15
|
|
|
@if($containsPublishedAtColumn) |
16
|
|
|
use Carbon\Carbon; |
17
|
|
|
@endif |
18
|
|
|
|
19
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
20
|
|
|
use Illuminate\Support\Facades\Gate; |
21
|
|
|
use Illuminate\Validation\Rule; |
22
|
|
|
|
23
|
|
|
class Update{{ $modelBaseName }} extends FormRequest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Determine if the user is authorized to make this request. |
27
|
|
|
* |
28
|
|
|
* {{'@'}}return bool |
29
|
|
|
*/ |
30
|
|
|
public function authorize(): bool |
31
|
|
|
{ |
32
|
|
|
return $this->user()->can('update', $this->{{ $modelVariableName }}); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Get the validation rules that apply to the request. |
37
|
|
|
* |
38
|
|
|
* {{'@'}}return array |
39
|
|
|
*/ |
40
|
|
|
public function rules(): array |
41
|
|
|
{ |
42
|
|
|
return [ |
43
|
|
|
@foreach($standardColumns as $column) |
44
|
|
|
@if(!($column['name'] == "updated_by_admin_user_id" || $column['name'] == "created_by_admin_user_id" ))'{{ $column['name'] }}' => [{!! implode(', ', (array) $column['serverUpdateRules']) !!}], |
45
|
|
|
@endif |
46
|
|
|
@endforeach |
47
|
|
|
@if (count($relations)) |
48
|
|
|
@if (isset($relations['belongsToMany']) && count($relations['belongsToMany'])) |
49
|
|
|
|
50
|
|
|
@foreach($relations['belongsToMany'] as $belongsToMany)'{{ $belongsToMany['related_table'] }}' => [{!! implode(', ', ['\'sometimes\'', '\'array\'']) !!}], |
51
|
|
|
@endforeach |
52
|
|
|
@endif |
53
|
|
|
@if (isset($relations["belongsTo"]) && count($relations['belongsTo'])) |
54
|
|
|
|
55
|
|
|
@foreach($relations['belongsTo'] as $belongsTo) |
56
|
|
|
'{{ $belongsTo['relationship_variable'] }}' => [{!! implode(', ', array_merge( |
57
|
|
|
['\'array\''], collect($relatableColumns[$belongsTo['foreign_key']]['serverUpdateRules'])->reject(function($rule){return str_contains($rule,'integer');})->toArray() |
58
|
|
|
)) !!}], |
59
|
|
|
@endforeach |
60
|
|
|
@endif |
61
|
|
|
@endif |
62
|
|
|
@if($containsPublishedAtColumn)'publish_now' => ['nullable', 'boolean'], |
63
|
|
|
'unpublish_now' => ['nullable', 'boolean'], |
64
|
|
|
@endif |
65
|
|
|
|
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Modify input data |
71
|
|
|
* |
72
|
|
|
* {{'@'}}return array |
73
|
|
|
*/ |
74
|
|
|
public function sanitizedArray(): array |
75
|
|
|
{ |
76
|
|
|
$sanitized = $this->validated(); |
77
|
|
|
|
78
|
|
|
@if($containsPublishedAtColumn) |
79
|
|
|
if (isset($sanitized['publish_now']) && $sanitized['publish_now'] === true) { |
80
|
|
|
$sanitized['published_at'] = Carbon::now(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (isset($sanitized['unpublish_now']) && $sanitized['unpublish_now'] === true) { |
84
|
|
|
$sanitized['published_at'] = null; |
85
|
|
|
} |
86
|
|
|
@endif |
87
|
|
|
|
88
|
|
|
//Add your code for manipulation with request data here |
89
|
|
|
|
90
|
|
|
return $sanitized; |
91
|
|
|
} |
92
|
|
|
/** |
93
|
|
|
* Return modified (sanitized data) as a php object |
94
|
|
|
* @return object |
95
|
|
|
*/ |
96
|
|
|
public function sanitizedObject(): object { |
97
|
|
|
$sanitized = $this->sanitizedArray(); |
98
|
|
|
return json_decode(collect($sanitized)); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed.
As a precaution to avoid these problems better use the long opening tag
<?php
.