diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.php index 1e47cf7506..163f1cd7ad 100644 --- a/app/Http/Controllers/Api/LocationsController.php +++ b/app/Http/Controllers/Api/LocationsController.php @@ -21,8 +21,10 @@ class LocationsController extends Controller public function index(Request $request) { $this->authorize('view', Location::class); - $allowed_columns = ['id','name','address','address2','city','state','country','zip','created_at', - 'updated_at','parent_id', 'manager_id','image']; + $allowed_columns = [ + 'id','name','address','address2','city','state','country','zip','created_at', + 'updated_at','parent_id', 'manager_id','image', + 'rtd_assets_count','users_count','assets_count']; $locations = Location::with('parent', 'manager', 'childLocations')->select([ 'locations.id', @@ -39,8 +41,7 @@ class LocationsController extends Controller 'locations.updated_at', 'locations.image', 'locations.currency' - ])->withCount('locationAssets') - ->withCount('assignedAssets') + ])->withCount('rtd_assets') ->withCount('assets') ->withCount('users'); diff --git a/app/Http/Transformers/LocationsTransformer.php b/app/Http/Transformers/LocationsTransformer.php index 2822968623..3009f93ead 100644 --- a/app/Http/Transformers/LocationsTransformer.php +++ b/app/Http/Transformers/LocationsTransformer.php @@ -39,8 +39,9 @@ class LocationsTransformer 'state' => e($location->state), 'country' => e($location->country), 'zip' => e($location->zip), - 'assets_checkedout' => $location->location_assets_count, - 'assets_default' => $location->assigned_assets_count, + 'assets_count' => (int) $location->assets_count, + 'rtd_assets_count' => (int) $location->rtd_assets_count, + 'users_count' => (int) $location->users_count, 'created_at' => Helper::getFormattedDateObject($location->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($location->updated_at, 'datetime'), diff --git a/app/Models/Location.php b/app/Models/Location.php index 3275c296d4..6a416a4173 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -54,10 +54,10 @@ class Location extends SnipeModel public function assets() { - return $this->hasManyThrough('\App\Models\Asset', '\App\Models\User', 'location_id', 'assigned_to', 'id')->where("assets.assigned_type",User::class); + return $this->hasMany('\App\Models\Asset', 'location_id'); } - public function locationAssets() + public function rtd_assets() { /* This used to have an ...->orHas() clause that referred to assignedAssets, and that was probably incorrect, as well as @@ -88,6 +88,7 @@ class Location extends SnipeModel return $this->hasMany('\App\Models\Location', 'parent_id'); } + // I don't think we need this anymore since we de-normed location_id in assets? public function assignedAssets() { return $this->morphMany('App\Models\Asset', 'assigned', 'assigned_type', 'assigned_to')->withTrashed(); diff --git a/resources/views/locations/index.blade.php b/resources/views/locations/index.blade.php index d6b5212fae..ab023f776e 100755 --- a/resources/views/locations/index.blade.php +++ b/resources/views/locations/index.blade.php @@ -31,8 +31,9 @@