gives a better example with custom fields in label preview

This commit is contained in:
Godfrey M 2024-02-15 11:50:41 -08:00
parent 5cbcac28b1
commit 250b0a7afb
2 changed files with 44 additions and 49 deletions

View file

@ -6,7 +6,6 @@ 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;
@ -27,24 +26,18 @@ class LabelsController extends Controller
*/
public function show(string $labelName)
{
$setting = Setting::getSettings();
//This part allows for the custom selection label preview
$data = explode(';', Setting::getSettings()->label2_fields);
$fields = str_replace('=', ' ', $data);
$data = array_map(function($element) {
$a = explode('=', $element);
return [$a[0] => $a[1]];
}, $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);
if($setting->label2_enable && ($setting->label2_template != 'DefaultLabel')) {
$exampleAsset = new Asset();
$exampleAsset->id = 999999;
@ -80,10 +73,12 @@ class LabelsController extends Controller
$exampleAsset->model->category = new Category();
$exampleAsset->model->category->id = 999999;
$exampleAsset->model->category->name = trans('admin/labels/table.example_category');
}
foreach($custom_fields as $key => $value){
$exampleAsset->{$key} = "{{$value}}" ;
foreach($data as $innerArray){
foreach($innerArray as $key => $value) {
$exampleAsset->{$value} = "{{$key}}";
}
}
$settings = Setting::getSettings();

View file

@ -1,4 +1,4 @@
@extends('layouts/default')
@extends('layouts/default')
{{-- Page title --}}
@section('title')