From 5cbcac28b10ac388133bb38c739c0029e73932a6 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 14 Feb 2024 16:53:38 -0800 Subject: [PATCH] adds custom fields as an example in label settings --- app/Http/Controllers/LabelsController.php | 21 +++++++++++++++++++++ resources/views/settings/labels.blade.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index bb08d2cd45..b518be878a 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -6,6 +6,7 @@ use App\Models\Asset; use App\Models\AssetModel; use App\Models\Category; use App\Models\Company; +use App\Models\CustomFieldset; use App\Models\Labels\Label; use App\Models\Location; use App\Models\Manufacturer; @@ -26,6 +27,21 @@ class LabelsController extends Controller */ public function show(string $labelName) { + $data = explode(';', Setting::getSettings()->label2_fields); + $fields = str_replace('=', ' ', $data); + + $custom_fields= []; + + foreach ($fields as $field) { + + $parts = explode('_', $field, 2); + + $key = trim($parts[0]); + $value = trim($parts[1]); + + $custom_fields["_".$value] = $key ; + } +// dd($custom_fields); $labelName = str_replace('/', '\\', $labelName); $template = Label::find($labelName); @@ -65,6 +81,11 @@ class LabelsController extends Controller $exampleAsset->model->category->id = 999999; $exampleAsset->model->category->name = trans('admin/labels/table.example_category'); + + foreach($custom_fields as $key => $value){ + $exampleAsset->{$key} = "{{$value}}" ; + } + $settings = Setting::getSettings(); if (request()->has('settings')) { $overrides = request()->get('settings'); diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php index a6edd29154..cfa7ba1785 100644 --- a/resources/views/settings/labels.blade.php +++ b/resources/views/settings/labels.blade.php @@ -1,4 +1,4 @@ -@extends('layouts/default') + @extends('layouts/default') {{-- Page title --}} @section('title')