Fixes #3792 - parent/child locations in API

This commit is contained in:
snipe 2017-08-25 05:32:12 -07:00
parent 29a7c8577d
commit 10711245ba
2 changed files with 6 additions and 9 deletions

View file

@ -22,14 +22,12 @@ class LocationsTransformer
{
if ($location) {
$assets_arr = [];
foreach($location->assets() as $asset) {
$assets_arr = ['id' => $asset->id];
}
$children_arr = [];
foreach($location->childLocations() as $child) {
$children_arr = ['id' => $child->id];
foreach($location->childLocations as $child) {
$children_arr[] = [
'id' => (int) $child->id,
'name' => $child->name
];
}
$array = [
@ -41,7 +39,6 @@ class LocationsTransformer
'assets_checkedout' => $location->assets()->count(),
'assets_default' => $location->assignedassets()->count(),
'country' => e($location->country),
'assets' => $assets_arr,
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
'parent' => ($location->parent) ? [

View file

@ -63,7 +63,7 @@ class Location extends SnipeModel
public function parent()
{
return $this->belongsTo('\App\Models\Location', 'parent_id');
return $this->belongsTo('\App\Models\Location', 'parent_id','id');
}
public function childLocations()