A free open source IT asset/license management system
add customlabelRequest for store and update methods, remove a gitignore
Godfrey M6b909560577b
diff --git a/.gitignore b/.gitignoreindex ec334da246..04705a850f 100755--- a/.gitignore+++ b/.gitignore@@ -21,7 +21,6 @@ Homestead.jsonHomestead.yamloutputphpDocumentor.phar-/public/build/public/uploads/*.gifpublic/uploads/barcodes/*.pngpublic/uploads/*.jpgdiff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.phpindex 99946df084..7aa44117c7 100755--- a/app/Http/Controllers/LabelsController.php+++ b/app/Http/Controllers/LabelsController.php@@ -2,23 +2,23 @@namespace App\Http\Controllers;-use App\Models\Asset;+use App\Http\Requests\CustomLabelRequest;use App\Models\CustomField;+use App\Models\Labels\CustomLabelFonts;use App\Models\Labels\CustomLabels\PreviewSheetLabel;use App\Models\Labels\CustomLabels\PreviewTapeLabel;use App\Models\Labels\CustomUserLabel;use App\Models\Labels\DefaultLabel;use App\Models\Labels\Label;+use App\Models\Labels\LabelPreviewAsset;+use App\Models\Labels\RectangleSheet;use App\Models\Setting;+use App\Rules\LabelGeometryRules;+use App\Services\CustomLabelImportValidator;use App\View\Label as LabelView;use Illuminate\Http\Request;-use Illuminate\Validation\ValidationException;-use App\Services\CustomLabelImportValidator;use Illuminate\Validation\Rule;-use App\Models\Labels\RectangleSheet;-use App\Models\Labels\LabelPreviewAsset;-use App\Models\Labels\LabelGeometryRules;-use App\Models\Labels\CustomLabelFonts;+use Illuminate\Validation\ValidationException;class LabelsController extends Controller{@@ -150,38 +150,14 @@ class LabelsController extends Controller]);}- public function update(Request $request, CustomUserLabel $label)+ public function update(CustomLabelRequest $request, CustomUserLabel $label){- $type = $request->input('type', $label->type ?? 'sheet');+ $validated = $request->validated();++ $type = $validated['type'];$isTape = $type === 'tape';- $rules = [- 'name' => ['required', 'string', 'max:255'],- 'type' => ['required', Rule::in(['sheet', 'tape'])],- 'content' => ['required', 'array'],- 'supports' => ['required', 'array'],- 'content.tag_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.title_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.field_label_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.field_value_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- ];- if ($isTape) {- $rules += [- 'dimensions' => ['required', 'array'],- 'dimensions.width' => ['required', 'numeric', 'gt:0'],- 'dimensions.height' => ['required', 'numeric', 'gt:0'],- 'dimensions.label_gap' => ['nullable', 'numeric', 'min:0'],- ];- } else {- $rules += [- 'page' => ['required', 'array'],- 'grid' => ['required', 'array'],- 'label' => ['required', 'array'],- ];- $rules += LabelGeometryRules::sheet();- }- $validated = $request->validate($rules);$supports = collect($validated['supports'])->map(function ($value, $key) {@@ -272,40 +248,12 @@ class LabelsController extends Controller->with('success', trans('admin/labels/general.updated_successfully', ['item' => $label->name]));}- public function store(Request $request)+ public function store(CustomLabelRequest $request){- $type = $request->input('type', 'sheet');-- $rules = [- 'name' => ['required', 'string', 'max:255'],- 'template' => ['nullable', 'string'],- 'type' => ['required', Rule::in(['sheet', 'tape'])],- 'content' => ['required', 'array'],- 'supports' => ['required', 'array'],- 'content.tag_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.title_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.field_label_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- 'content.field_value_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED),],- ];+ $validated = $request->validated();- if ($type === 'sheet') {- $rules += [- 'page' => ['required', 'array'],- 'grid' => ['required', 'array'],- 'label' => ['required', 'array'],- ];- $rules += LabelGeometryRules::sheet();- }- if ($type === 'tape') {- $rules += [- 'dimensions' => ['required', 'array'],- 'dimensions.width' => ['required', 'numeric', 'gt:0'],- 'dimensions.height' => ['required', 'numeric', 'gt:0'],- 'dimensions.label_gap' => ['nullable', 'numeric', 'min:0'],- ];- }+ $type = $validated['type'];- $validated = $request->validate($rules);$supports = collect($validated['supports'])->map(function ($value, $key) {diff --git a/app/Http/Requests/CustomLabelRequest.php b/app/Http/Requests/CustomLabelRequest.phpnew file mode 100644index 0000000000..67b8eed122--- /dev/null+++ b/app/Http/Requests/CustomLabelRequest.php@@ -0,0 +1,54 @@+<?php++namespace App\Http\Requests;++use App\Models\Labels\CustomLabelFonts;+use App\Rules\LabelGeometryRules;+use Illuminate\Foundation\Http\FormRequest;+use Illuminate\Validation\Rule;++class CustomLabelRequest extends FormRequest+{+ public function authorize(): bool+ {+ return true;+ }++ public function rules(): array+ {+ return $this->commonRules() + ($this->input('type') === 'tape' ? $this->tapeRules() : $this->sheetRules());+ }++ private function commonRules(): array+ {+ return [+ 'name' => ['required', 'string', 'max:255'],+ 'type' => ['required', Rule::in(['sheet', 'tape'])],+ 'content' => ['required', 'array'],+ 'supports' => ['required', 'array'],+ 'content.tag_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.title_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.field_label_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ 'content.field_value_font' => ['nullable', 'string', Rule::in(CustomLabelFonts::ALLOWED)],+ ];+ }++ private function tapeRules(): array+ {+ return [+ 'dimensions' => ['required', 'array'],+ 'dimensions.width' => ['required', 'numeric', 'gt:0'],+ 'dimensions.height' => ['required', 'numeric', 'gt:0'],+ 'dimensions.label_gap' => ['nullable', 'numeric', 'min:0'],+ ];+ }++ private function sheetRules(): array+ {+ return [+ 'page' => ['required', 'array'],+ 'grid' => ['required', 'array'],+ 'label' => ['required', 'array'],+ ] + LabelGeometryRules::sheet();+ }+}\ No newline at end of filediff --git a/app/Models/Labels/LabelGeometryRules.php b/app/Rules/LabelGeometryRules.phpsimilarity index 97%rename from app/Models/Labels/LabelGeometryRules.phprename to app/Rules/LabelGeometryRules.phpindex 59c7fadba9..a96eefdc71 100644--- a/app/Models/Labels/LabelGeometryRules.php+++ b/app/Rules/LabelGeometryRules.php@@ -1,6 +1,6 @@<?php-namespace App\Models\Labels;+namespace App\Rules;final class LabelGeometryRules{diff --git a/app/Services/CustomLabelImportValidator.php b/app/Services/CustomLabelImportValidator.phpindex 997c726ae8..5c1ad03673 100644--- a/app/Services/CustomLabelImportValidator.php+++ b/app/Services/CustomLabelImportValidator.php@@ -2,10 +2,11 @@namespace App\Services;-use App\Models\Labels\LabelGeometryRules;-use Illuminate\Validation\ValidationException;-use Illuminate\Validation\Rule;use App\Models\Labels\CustomLabelFonts;+use App\Rules\LabelGeometryRules;+use Illuminate\Validation\Rule;+use Illuminate\Validation\ValidationException;+class CustomLabelImportValidator{public function validate(?string $rawJson): array