From 69317fb40367d8d74347bf44f05235613a787ac4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 15 Feb 2024 13:26:47 -0800 Subject: [PATCH] Marcus is a beast and condensed everything into 4 lines --- app/Http/Controllers/LabelsController.php | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index 80ace3084a..7ea6843d4f 100755 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -26,20 +26,6 @@ class LabelsController extends Controller */ public function show(string $labelName) { - $setting = Setting::getSettings(); - - //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); @@ -79,9 +65,12 @@ class LabelsController extends Controller $exampleAsset->model->category->id = 999999; $exampleAsset->model->category->name = trans('admin/labels/table.example_category'); - foreach($field_selections as $key => $value) { - $exampleAsset->{$value} = "{{$key}}"; - } + collect(explode(';', Setting::getSettings()->label2_fields)) + ->each(function ($item) use ($exampleAsset){ + $pair = explode('=', $item); + + $exampleAsset->{$pair[1]} = "{{$pair[0]}}"; + }); $settings = Setting::getSettings(); if (request()->has('settings')) {