1
|
|
|
@php echo "<?php" |
|
|
|
|
2
|
|
|
@endphp |
3
|
|
|
|
4
|
|
|
namespace App\Http\Requests\{{ $modelWithNamespaceFromDefault }}; |
5
|
|
|
@php |
6
|
|
|
$standardColumns = $columns->reject(function($column) use ($relatable) { |
7
|
|
|
return in_array($column['name'], $relatable->pluck('name')->toArray())|| $column["name"]=='slug'; |
8
|
|
|
}); |
9
|
|
|
$relatableColumns = $columns->filter(function($column) use ($relatable) { |
10
|
|
|
return in_array($column['name'], $relatable->pluck('name')->toArray()); |
11
|
|
|
})->keyBy('name'); |
12
|
|
|
@endphp |
13
|
|
|
|
14
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
15
|
|
|
use Illuminate\Support\Facades\Gate; |
16
|
|
|
use Illuminate\Validation\Rule; |
17
|
|
|
use {{$modelFullName}}; |
18
|
|
|
class Store{{ $modelBaseName }} extends FormRequest |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Determine if the user is authorized to make this request. |
22
|
|
|
* |
23
|
|
|
* {{'@'}}return bool |
24
|
|
|
*/ |
25
|
|
|
public function authorize(): bool |
26
|
|
|
{ |
27
|
|
|
return $this->user()->can('create',{{$modelBaseName}}::class); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get the validation rules that apply to the request. |
32
|
|
|
* |
33
|
|
|
* {{'@'}}return array |
34
|
|
|
*/ |
35
|
|
|
public function rules(): array |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
@foreach($standardColumns as $column) |
39
|
|
|
@if(!($column['name'] == "updated_by_admin_user_id" || $column['name'] == "created_by_admin_user_id" ))'{{ $column['name'] }}' => [{!! implode(', ', (array) $column['serverStoreRules']) !!}], |
40
|
|
|
@endif |
41
|
|
|
@endforeach |
42
|
|
|
@if (count($relations)) |
43
|
|
|
@if (isset($relations["belongsToMany"]) && count($relations['belongsToMany'])) |
44
|
|
|
|
45
|
|
|
@foreach($relations['belongsToMany'] as $belongsToMany)'{{ $belongsToMany['related_table'] }}' => [{!! implode(', ', ['\'array\'']) !!}], |
46
|
|
|
@endforeach |
47
|
|
|
@endif |
48
|
|
|
@if (isset($relations["belongsTo"]) && count($relations['belongsTo'])) |
49
|
|
|
|
50
|
|
|
@foreach($relations['belongsTo'] as $belongsTo) |
51
|
|
|
'{{ $belongsTo['relationship_variable'] }}' => [{!! implode(', ', array_merge( |
52
|
|
|
['\'array\''], collect($relatableColumns[$belongsTo['foreign_key']]['serverStoreRules'])->reject(function($rule){return str_contains($rule,'integer');})->toArray() |
53
|
|
|
)) !!}], |
54
|
|
|
@endforeach |
55
|
|
|
@endif |
56
|
|
|
@endif |
57
|
|
|
|
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* Modify input data |
62
|
|
|
* |
63
|
|
|
* {{'@'}}return array |
64
|
|
|
*/ |
65
|
|
|
public function sanitizedArray(): array |
66
|
|
|
{ |
67
|
|
|
$sanitized = $this->validated(); |
68
|
|
|
|
69
|
|
|
//Add your code for manipulation with request data here |
70
|
|
|
|
71
|
|
|
return $sanitized; |
72
|
|
|
} |
73
|
|
|
/** |
74
|
|
|
* Return modified (sanitized data) as a php object |
75
|
|
|
* @return object |
76
|
|
|
*/ |
77
|
|
|
public function sanitizedObject(): object { |
78
|
|
|
$sanitized = $this->sanitizedArray(); |
79
|
|
|
return json_decode(collect($sanitized)); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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
.