does a collect and map instead of a for loop for the array solution

This commit is contained in:
Godfrey M 2024-02-15 12:34:09 -08:00
parent 414bc10c40
commit 70f26f33a5

View file

@ -74,16 +74,16 @@ 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
$result = array(); //turns a multidimensional array in an associative array
foreach ($data as $entry) { $field_selections = collect($data)->mapWithKeys(function ($item) {
$result[key($entry)] = reset($entry); return $item;
} })->toArray();
foreach($result as $key => $value) {
foreach($field_selections as $key => $value) {
$exampleAsset->{$value} = "{{$key}}"; $exampleAsset->{$value} = "{{$key}}";
} }
$settings = Setting::getSettings(); $settings = Setting::getSettings();
if (request()->has('settings')) { if (request()->has('settings')) {
$overrides = request()->get('settings'); $overrides = request()->get('settings');