mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Format assigned to field
This commit is contained in:
parent
a47e36c1e5
commit
4675f02349
|
@ -14,6 +14,14 @@ class FieldOption {
|
||||||
|
|
||||||
public function getValue(Asset $asset) {
|
public function getValue(Asset $asset) {
|
||||||
$dataPath = collect(explode('.', $this->dataSource));
|
$dataPath = collect(explode('.', $this->dataSource));
|
||||||
|
|
||||||
|
// assignedTo directly on the asset is a special case where
|
||||||
|
// we want to avoid returning the property directly
|
||||||
|
// and instead return the entity's presented name.
|
||||||
|
if ($dataPath[0] === 'assignedTo'){
|
||||||
|
return $asset->assignedTo->present()->fullName();
|
||||||
|
}
|
||||||
|
|
||||||
return $dataPath->reduce(function ($myValue, $path) {
|
return $dataPath->reduce(function ($myValue, $path) {
|
||||||
try { return $myValue ? $myValue->{$path} : ${$myValue}; }
|
try { return $myValue ? $myValue->{$path} : ${$myValue}; }
|
||||||
catch (\Exception $e) { return $myValue; }
|
catch (\Exception $e) { return $myValue; }
|
||||||
|
@ -46,4 +54,4 @@ class FieldOption {
|
||||||
return $option;
|
return $option;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue