mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Add in location parent and child information into API requests (#3582)
* Add location hierarchy to LocationsTransformer * Add in parent_id
This commit is contained in:
parent
dcfc434075
commit
0ab37af7ab
|
@ -21,7 +21,7 @@ class LocationsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Location::class);
|
$this->authorize('view', Location::class);
|
||||||
$allowed_columns = ['id','name','address','address2','city','state','country','zip','created_at',
|
$allowed_columns = ['id','name','address','address2','city','state','country','zip','created_at',
|
||||||
'updated_at'];
|
'updated_at','parent_id'];
|
||||||
|
|
||||||
$locations = Location::select([
|
$locations = Location::select([
|
||||||
'locations.id',
|
'locations.id',
|
||||||
|
|
|
@ -26,6 +26,11 @@ class LocationsTransformer
|
||||||
foreach($location->assets() as $asset) {
|
foreach($location->assets() as $asset) {
|
||||||
$assets_arr = ['id' => $asset->id];
|
$assets_arr = ['id' => $asset->id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$children_arr = [];
|
||||||
|
foreach($location->childLocations() as $child) {
|
||||||
|
$children_arr = ['id' => $child->id];
|
||||||
|
}
|
||||||
|
|
||||||
$array = [
|
$array = [
|
||||||
'id' => e($location->id),
|
'id' => e($location->id),
|
||||||
|
@ -39,6 +44,8 @@ class LocationsTransformer
|
||||||
'assets' => $assets_arr,
|
'assets' => $assets_arr,
|
||||||
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
|
'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'),
|
||||||
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
|
'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'),
|
||||||
|
'parent_id' => e($location->parent_id),
|
||||||
|
'children' => $children_arr,
|
||||||
];
|
];
|
||||||
|
|
||||||
$permissions_array['available_actions'] = [
|
$permissions_array['available_actions'] = [
|
||||||
|
|
Loading…
Reference in a new issue