From 83474d6e5980953d44974a323a697601af2c005b Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 15 Feb 2024 12:59:47 -0800 Subject: [PATCH] moves the array manipulation up the page where it should be --- app/Http/Controllers/LabelsController.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index 3a8ff4faf5..6363ee671a 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -27,13 +27,18 @@ class LabelsController extends Controller public function show(string $labelName) { $setting = Setting::getSettings(); - //This part allows for the custom field selection to be visible in the label preview + //grabs the field selection selected and turns it into a multidimensional array $data = explode(';', Setting::getSettings()->label2_fields); $data = array_map(function($element) { $a = explode('=', $element); return [$a[0] => $a[1]]; }, $data); + //turns a multidimensional array into an associative array + $field_selections = collect($data)->mapWithKeys(function ($item) { + return $item; + })->toArray(); + $labelName = str_replace('/', '\\', $labelName); $template = Label::find($labelName); @@ -75,10 +80,7 @@ class LabelsController extends Controller $exampleAsset->model->category->name = trans('admin/labels/table.example_category'); } - //turns a multidimensional array into an associative array - $field_selections = collect($data)->mapWithKeys(function ($item) { - return $item; - })->toArray(); + foreach($field_selections as $key => $value) { $exampleAsset->{$value} = "{{$key}}";