A free open source IT asset/license management system
Removed a few duplicate queries
snipeec67195014b4
diff --git a/app/Http/Controllers/Api/LocationsController.php b/app/Http/Controllers/Api/LocationsController.phpindex 840e30a128..481de7bb5f 100644--- a/app/Http/Controllers/Api/LocationsController.php+++ b/app/Http/Controllers/Api/LocationsController.php@@ -67,7 +67,18 @@ class LocationsController extends Controller'notes',];- $locations = Location::with('parent', 'manager', 'children')->select([+ $locations = Location::with([+ 'parent',+ 'children',+ 'manager' => fn ($q) => $q->withCount([+ 'assets as assets_count',+ 'accessories as accessories_count',+ 'licenses as licenses_count',+ 'consumables as consumables_count',+ 'managesUsers as manages_users_count',+ 'managedLocations as manages_locations_count',+ ]),+ ])->select(['locations.id','locations.name','locations.address',@@ -157,8 +168,6 @@ class LocationsController extends Controller$locations->where('tag_color', '=', $request->input('locations.tag_color'));}- // Make sure the offset and limit are actually integers and do not exceed system limits- $offset = ($request->input('offset') > $locations->count()) ? $locations->count() : app('api_offset_value');$limit = app('api_limit_value');$order = $request->input('order') === 'asc' ? 'asc' : 'desc';@@ -180,6 +189,7 @@ class LocationsController extends Controller}$total = $locations->count();+ $offset = ($request->input('offset') > $total) ? $total : app('api_offset_value');$locations = $locations->skip($offset)->take($limit)->get();return (new LocationsTransformer)->transformLocations($locations, $total);@@ -227,7 +237,19 @@ class LocationsController extends Controllerpublic function show($id): JsonResponse|array{$this->authorize('view', Location::class);- $location = Location::with('parent', 'manager', 'children', 'company')+ $location = Location::with([+ 'parent',+ 'children',+ 'company',+ 'manager' => fn ($q) => $q->withCount([+ 'assets as assets_count',+ 'accessories as accessories_count',+ 'licenses as licenses_count',+ 'consumables as consumables_count',+ 'managesUsers as manages_users_count',+ 'managedLocations as manages_locations_count',+ ]),+ ])->select(['locations.id','locations.name',diff --git a/app/Models/User.php b/app/Models/User.phpindex 2957a058fe..2b84feb093 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -601,7 +601,6 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo&& (($this->accessories_count ?? $this->accessories()->count()) === 0)&& (($this->licenses_count ?? $this->licenses()->count()) === 0)&& (($this->consumables_count ?? $this->consumables()->count()) === 0)- && (($this->accessories_count ?? $this->accessories()->count()) === 0)&& (($this->manages_users_count ?? $this->managesUsers()->count()) === 0)&& (($this->manages_locations_count ?? $this->managedLocations()->count()) === 0)&& ($this->deleted_at == '');diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.phpindex a6a4e79127..01c795a35f 100644--- a/app/Providers/AppServiceProvider.php+++ b/app/Providers/AppServiceProvider.php@@ -23,11 +23,13 @@ use App\Observers\LocationObserver;use App\Observers\MaintenanceObserver;use App\Observers\SettingObserver;use App\Observers\UserObserver;+use App\View\Composers\SidebarComposer;use Illuminate\Pagination\Paginator;use Illuminate\Routing\UrlGenerator;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Schema;use Illuminate\Support\Facades\URL;+use Illuminate\Support\Facades\View;use Illuminate\Support\ServiceProvider;use Rollbar\Laravel\RollbarServiceProvider;@@ -75,6 +77,8 @@ class AppServiceProvider extends ServiceProviderPaginator::useBootstrap();+ View::composer('layouts.default', SidebarComposer::class);+Schema::defaultStringLength(191);Accessory::observe(AccessoryObserver::class);Asset::observe(AssetObserver::class);diff --git a/app/Providers/SettingsServiceProvider.php b/app/Providers/SettingsServiceProvider.phpindex 7c1ddcddad..a0e79490e5 100644--- a/app/Providers/SettingsServiceProvider.php+++ b/app/Providers/SettingsServiceProvider.php@@ -30,6 +30,7 @@ class SettingsServiceProvider extends ServiceProvider// Share common setting variables with all views.view()->composer('*', function ($view) {$view->with('snipeSettings', Setting::getSettings());+ $view->with('settings', Setting::getSettings());});/**