fix : 컨트롤러 검증 → FormRequest 분리
This commit is contained in:
28
app/Http/Requests/Design/BomTemplate/ReplaceItemsRequest.php
Normal file
28
app/Http/Requests/Design/BomTemplate/ReplaceItemsRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Design\BomTemplate;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use App\Support\Validation\BomItemRules;
|
||||
|
||||
class ReplaceItemsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$itemRules = collect(BomItemRules::base())
|
||||
->mapWithKeys(fn($rule, $key) => ["items.*.$key" => $rule])
|
||||
->all();
|
||||
|
||||
return ['items' => 'required|array|min:1'] + $itemRules;
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'items.required' => __('validation.required', ['attribute' => 'items']),
|
||||
'items.array' => __('validation.array', ['attribute' => 'items']),
|
||||
'items.min' => __('validation.min.array', ['attribute' => 'items', 'min' => 1]),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Requests/Design/BomTemplate/UpsertRequest.php
Normal file
22
app/Http/Requests/Design/BomTemplate/UpsertRequest.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Design\BomTemplate;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpsertRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:100',
|
||||
'is_primary' => 'nullable|boolean',
|
||||
'notes' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Http/Requests/Design/Model/StoreRequest.php
Normal file
36
app/Http/Requests/Design/Model/StoreRequest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\Http\Requests\Design\Model;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool { return true; }
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code' => 'required|string|max:100',
|
||||
'name' => 'required|string|max:200',
|
||||
'category_id' => 'nullable|integer',
|
||||
'lifecycle' => 'nullable|string|max:50',
|
||||
'description' => 'nullable|string',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'code.required' => __('validation.required', ['attribute' => '모델코드']),
|
||||
'name.required' => __('validation.required', ['attribute' => '모델명']),
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('code')) {
|
||||
$this->merge(['code' => trim($this->input('code'))]);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
app/Http/Requests/Design/Model/UpdateRequest.php
Normal file
25
app/Http/Requests/Design/Model/UpdateRequest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Design\Model;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'code' => 'sometimes|string|max:100',
|
||||
'name' => 'sometimes|string|max:200',
|
||||
'category_id' => 'nullable|integer',
|
||||
'lifecycle' => 'nullable|string|max:50',
|
||||
'description' => 'nullable|string',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Design/ModelVersion/CreateDraftRequest.php
Normal file
30
app/Http/Requests/Design/ModelVersion/CreateDraftRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Design\ModelVersion;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateDraftRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'version_no' => 'nullable|integer|min:1',
|
||||
'notes' => 'nullable|string',
|
||||
'effective_from' => 'nullable|date',
|
||||
'effective_to' => 'nullable|date|after_or_equal:effective_from',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'effective_to.after_or_equal' => __('validation.after_or_equal', ['attribute' => 'effective_to', 'date' => 'effective_from']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user