A free open source IT asset/license management system
building the store method, add customuserLabel model
Godfrey M06393340a544
diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.phpindex f42c68931c..a065da0423 100755--- a/app/Http/Controllers/LabelsController.php+++ b/app/Http/Controllers/LabelsController.php@@ -7,6 +7,7 @@ use App\Models\AssetModel;use App\Models\Category;use App\Models\Company;use App\Models\CustomField;+use App\Models\Labels\CustomUserLabel;use App\Models\Labels\DefaultLabel;use App\Models\Labels\Label;use App\Models\Location;@@ -99,6 +100,73 @@ class LabelsController extends Controller}+ public function store(Request $request)+ {++ $validated = $request->validate([+ 'name' => ['required', 'string', 'max:255'],+ 'template' => ['nullable', 'string'],+ 'type' => ['nullable', 'string'],+ 'page' => ['required', 'array'],+ 'grid' => ['required', 'array'],+ 'label' => ['required', 'array'],+ 'content' => ['required', 'array'],+ 'supports' => ['required', 'array'],+ ]);++ $supports = collect($validated['supports'])+ ->map(fn($value) => (bool)$value)+ ->toArray();++ $castNumeric = function ($array) {+ return collect($array)->map(function ($value) {+ if (is_numeric($value)) {+ return (float)$value;+ }+ return $value;+ })->toArray();+ };++ $page = $castNumeric($validated['page']);+ $grid = $castNumeric($validated['grid']);+ $label = $castNumeric($validated['label']);+ $content = $castNumeric($validated['content']);+ $baseLabel = Models\Labels\+ $finalConfig = [+ 'page' => $page,+ 'grid' => $grid,+ 'label' => $label,+ 'content' => $content,+ 'supports' => $supports,+ ];+ $baseConfig = [+ 'page' => $baseLabel->getPageEditorConfig(),+ 'grid' => $baseLabel->getGridEditorConfig(),+ 'label' => $baseLabel->getLabelEditorConfig(),+ 'content' => $baseLabel->getContentEditorConfig(),+ 'supports' => $baseLabel->getSupportsEditorConfig(),+ ];++ $configSnapshot = [+ 'template' => $validated['template'],+ 'type' => $validated['type'] ?? 'sheet',+ 'name' => $validated['name'],+ ...$overrides,+ ];++ $label = CustomUserLabel::create([+ 'name' => $validated['name'],+ 'base_label' => $validated['template'] ?? null,+ 'type' => $validated['type'] ?? 'sheet',+ 'overrides' => $overrides,+ 'config_snapshot' => $configSnapshot,+ 'is_default' => false,+ ]);++ return app(SettingsController::class)->getLabels()+ ->with('success', $label['name'] . ' created successfully.');+ }+public function edit(Request $request){$selectedLabel = $request->get('label');diff --git a/app/Models/Labels/CustomLabels/CustomSheetLabel.php b/app/Models/Labels/CustomLabels/CustomSheetLabel.phpindex ae2bb38481..a0e2e3b6cb 100644--- a/app/Models/Labels/CustomLabels/CustomSheetLabel.php+++ b/app/Models/Labels/CustomLabels/CustomSheetLabel.php@@ -598,7 +598,7 @@ abstract class CustomSheetLabel extends CustomLabel/*|--------------------------------------------------------------------------- | 3) Derive remaining text box+ | Derive remaining text box|--------------------------------------------------------------------------*/$layout['text'] = $this->resolveTextBox(diff --git a/app/Models/Labels/CustomUserLabel.php b/app/Models/Labels/CustomUserLabel.phpnew file mode 100644index 0000000000..dee582b1bb--- /dev/null+++ b/app/Models/Labels/CustomUserLabel.php@@ -0,0 +1,52 @@+<?php++namespace App\Models\Labels;++use Illuminate\Database\Eloquent\Model;++class CustomUserLabel extends Model+{+ protected $table = 'custom_user_labels';++ protected $fillable = [+ 'name',+ 'base_label',+ 'type',+ 'overrides',+ 'config_snapshot',+ 'is_default',+ ];++ protected $casts = [+ 'overrides' => 'array',+ 'config_snapshot' => 'array',+ 'is_default' => 'boolean',+ ];+++ public function applyOverrides(array $config): array+ {+ return array_merge($config, $this->overrides ?? []);+ }++ protected function resolveLabelClass(string $template): string+ {+ // Custom labels first+ $custom = "App\\Models\\Labels\\CustomLabels\\{$template}";+ if (class_exists($custom)) {+ return $custom;+ }++ // Avery sheets+ if (!str_starts_with($template, '_') && !str_starts_with($template, 'L')) {+ $template = '_' . $template;+ }++ $avery = "App\\Models\\Labels\\Sheets\\Avery\\{$template}";+ if (class_exists($avery)) {+ return $avery;+ }++ throw new \InvalidArgumentException("Unknown label template: {$template}");+ }+}\ No newline at end of filediff --git a/database/migrations/2026_03_23_184904_create_custom_labels_table.php b/database/migrations/2026_03_23_184904_create_custom_labels_table.phpindex 8bb933fef0..028a98f0b9 100644--- a/database/migrations/2026_03_23_184904_create_custom_labels_table.php+++ b/database/migrations/2026_03_23_184904_create_custom_labels_table.php@@ -11,13 +11,13 @@ return new class extends Migration*/public function up(): void{- Schema::create('custom_labels', function (Blueprint $table) {+ Schema::create('custom_user_labels', function (Blueprint $table) {$table->id();$table->string('name');$table->string('base_label')->nullable();$table->string('type')->default('sheet');$table->json('overrides')->nullable();- $table->json('config_snapshot')->nullable();+ $table->json('config_snapshot')->nullable(); //change to text$table->boolean('is_default')->default(false);$table->timestamps();});@@ -28,6 +28,6 @@ return new class extends Migration*/public function down(): void{- Schema::dropIfExists('custom_labels');+ Schema::dropIfExists('custom_user_labels');}};diff --git a/resources/views/settings/label-edit.blade.php b/resources/views/settings/label-edit.blade.phpindex ce0dbccdab..0272e88db6 100644--- a/resources/views/settings/label-edit.blade.php+++ b/resources/views/settings/label-edit.blade.php@@ -82,7 +82,8 @@</div></fieldset><div class="label-form-scroll">- <form id="label-customizer-form" method="POST" action="#" class="form-horizontal">+ <form id="label-customizer-form" method="POST" action="{{route('settings.labels.store')}}"+ class="form-horizontal">@csrf@phpdiff --git a/routes/web.php b/routes/web.phpindex ecdce98b0d..da46727d30 100644--- a/routes/web.php+++ b/routes/web.php@@ -210,7 +210,9 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuserRoute::get('/settings/labels/edit', [LabelsController::class, 'edit'])->name('settings.labels.edit');-+ Route::post('/settings/labels', [LabelsController::class, 'store'])+ ->name('settings.labels.store');+Route::get('ldap', [SettingsController::class, 'getLdapSettings'])->name('settings.ldap.index')->breadcrumbs(fn (Trail $trail) => $trail->parent('settings.index')