removes the double for loop with a better solution

This commit is contained in:
Godfrey M 2024-02-15 12:02:08 -08:00
parent 250b0a7afb
commit 414bc10c40

View file

@ -27,7 +27,7 @@ class LabelsController extends Controller
public function show(string $labelName) public function show(string $labelName)
{ {
$setting = Setting::getSettings(); $setting = Setting::getSettings();
//This part allows for the custom selection label preview //This part allows for the custom field selection to be visible in the label preview
$data = explode(';', Setting::getSettings()->label2_fields); $data = explode(';', Setting::getSettings()->label2_fields);
$data = array_map(function($element) { $data = array_map(function($element) {
$a = explode('=', $element); $a = explode('=', $element);
@ -74,12 +74,15 @@ class LabelsController extends Controller
$exampleAsset->model->category->id = 999999; $exampleAsset->model->category->id = 999999;
$exampleAsset->model->category->name = trans('admin/labels/table.example_category'); $exampleAsset->model->category->name = trans('admin/labels/table.example_category');
} }
//turns a multidimensional array in an associative array for no double for looping
foreach($data as $innerArray){ $result = array();
foreach($innerArray as $key => $value) { foreach ($data as $entry) {
$exampleAsset->{$value} = "{{$key}}"; $result[key($entry)] = reset($entry);
}
} }
foreach($result as $key => $value) {
$exampleAsset->{$value} = "{{$key}}";
}
$settings = Setting::getSettings(); $settings = Setting::getSettings();
if (request()->has('settings')) { if (request()->has('settings')) {