mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-23 12:44:12 -08:00
Update withCounts because Laravel 5.5 :(
This commit is contained in:
parent
e6dd90e055
commit
0714ac4248
|
@ -39,7 +39,7 @@ class SyncAssetCounters extends Command
|
|||
public function handle()
|
||||
{
|
||||
$start = microtime(true);
|
||||
$assets = Asset::withCount('checkins', 'checkouts', 'userRequests')
|
||||
$assets = Asset::withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')
|
||||
->withTrashed()->get();
|
||||
|
||||
if ($assets) {
|
||||
|
|
|
@ -281,9 +281,9 @@ class Helper
|
|||
*/
|
||||
public static function checkLowInventory()
|
||||
{
|
||||
$consumables = Consumable::withCount('consumableAssignments')->whereNotNull('min_amt')->get();
|
||||
$accessories = Accessory::withCount('users')->whereNotNull('min_amt')->get();
|
||||
$components = Component::withCount('assets')->whereNotNull('min_amt')->get();
|
||||
$consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
|
||||
$accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
|
||||
$components = Component::withCount('assets as assets_count')->whereNotNull('min_amt')->get();
|
||||
|
||||
$avail_consumables = 0;
|
||||
$items_array = array();
|
||||
|
|
|
@ -48,7 +48,7 @@ class AssetModelsController extends Controller
|
|||
'models.updated_at',
|
||||
])
|
||||
->with('category','depreciation', 'manufacturer','fieldset')
|
||||
->withCount('assets');
|
||||
->withCount('assets as assets_count');
|
||||
|
||||
|
||||
|
||||
|
@ -114,7 +114,7 @@ class AssetModelsController extends Controller
|
|||
public function show($id)
|
||||
{
|
||||
$this->authorize('view', AssetModel::class);
|
||||
$assetmodel = AssetModel::withCount('assets')->findOrFail($id);
|
||||
$assetmodel = AssetModel::withCount('assets as assets_count')->findOrFail($id);
|
||||
return (new AssetModelsTransformer)->transformAssetModel($assetmodel);
|
||||
}
|
||||
|
||||
|
|
|
@ -325,7 +325,8 @@ class AssetsController extends Controller
|
|||
*/
|
||||
public function show($id)
|
||||
{
|
||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()->withCount('checkins', 'checkouts', 'userRequests')->findOrFail($id)) {
|
||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()
|
||||
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->findOrFail($id)) {
|
||||
$this->authorize('view', $asset);
|
||||
return (new AssetsTransformer)->transformAsset($asset);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class CategoriesController extends Controller
|
|||
$allowed_columns = ['id', 'name','category_type', 'category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count','licenses_count', 'image'];
|
||||
|
||||
$categories = Category::select(['id', 'created_at', 'updated_at', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email','image'])
|
||||
->withCount('assets', 'accessories', 'consumables', 'components','licenses');
|
||||
->withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count','licenses as licenses_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$categories = $categories->TextSearch($request->input('search'));
|
||||
|
|
|
@ -35,7 +35,7 @@ class CompaniesController extends Controller
|
|||
'components_count',
|
||||
];
|
||||
|
||||
$companies = Company::withCount('assets','licenses','accessories','consumables','components','users');
|
||||
$companies = Company::withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count','components as components_count','users as users_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$companies->TextSearch($request->input('search'));
|
||||
|
|
|
@ -43,7 +43,7 @@ class CustomFieldsetsController extends Controller
|
|||
public function index()
|
||||
{
|
||||
$this->authorize('index', CustomFieldset::class);
|
||||
$fieldsets = CustomFieldset::withCount(['fields', 'models'])->get();
|
||||
$fieldsets = CustomFieldset::withCount('fields as fields_count', 'models as models_count')->get();
|
||||
return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count());
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ class DepartmentsController extends Controller
|
|||
'departments.created_at',
|
||||
'departments.updated_at',
|
||||
'departments.image'
|
||||
])->with('users')->with('location')->with('manager')->with('company')->withCount('users');
|
||||
])->with('users')->with('location')->with('manager')->with('company')->withCount('users as users_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$departments = $departments->TextSearch($request->input('search'));
|
||||
|
|
|
@ -22,7 +22,7 @@ class GroupsController extends Controller
|
|||
$this->authorize('view', Group::class);
|
||||
$allowed_columns = ['id','name','created_at', 'users_count'];
|
||||
|
||||
$groups = Group::select('id','name','permissions','created_at','updated_at')->withCount('users');
|
||||
$groups = Group::select('id','name','permissions','created_at','updated_at')->withCount('users as users_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$groups = $groups->TextSearch($request->input('search'));
|
||||
|
|
|
@ -25,7 +25,7 @@ class LicensesController extends Controller
|
|||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('view', License::class);
|
||||
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier','category')->withCount('freeSeats'));
|
||||
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier','category')->withCount('freeSeats as free_seats_count'));
|
||||
|
||||
|
||||
if ($request->has('company_id')) {
|
||||
|
|
|
@ -41,9 +41,9 @@ class LocationsController extends Controller
|
|||
'locations.updated_at',
|
||||
'locations.image',
|
||||
'locations.currency'
|
||||
])->withCount('assignedAssets')
|
||||
->withCount('assets')
|
||||
->withCount('users');
|
||||
])->withCount('assignedAssets as assigned_assets_count')
|
||||
->withCount('assets as assets_count')
|
||||
->withCount('users as users_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$locations = $locations->TextSearch($request->input('search'));
|
||||
|
|
|
@ -26,7 +26,7 @@ class ManufacturersController extends Controller
|
|||
|
||||
$manufacturers = Manufacturer::select(
|
||||
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'deleted_at')
|
||||
)->withCount('assets')->withCount('licenses')->withCount('consumables')->withCount('accessories');
|
||||
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count');
|
||||
|
||||
if ($request->input('deleted')=='true') {
|
||||
$manufacturers->onlyTrashed();
|
||||
|
|
|
@ -24,7 +24,7 @@ class StatuslabelsController extends Controller
|
|||
$this->authorize('view', Statuslabel::class);
|
||||
$allowed_columns = ['id','name','created_at', 'assets_count','color','default_label'];
|
||||
|
||||
$statuslabels = Statuslabel::withCount('assets');
|
||||
$statuslabels = Statuslabel::withCount('assets as assets_count');
|
||||
|
||||
if ($request->has('search')) {
|
||||
$statuslabels = $statuslabels->TextSearch($request->input('search'));
|
||||
|
@ -162,7 +162,7 @@ class StatuslabelsController extends Controller
|
|||
{
|
||||
$this->authorize('view', Statuslabel::class);
|
||||
|
||||
$statuslabels = Statuslabel::with('assets')->groupBy('id')->withCount('assets')->get();
|
||||
$statuslabels = Statuslabel::with('assets')->groupBy('id')->withCount('assets as assets_count')->get();
|
||||
|
||||
$labels=[];
|
||||
$points=[];
|
||||
|
|
|
@ -26,7 +26,7 @@ class SuppliersController extends Controller
|
|||
|
||||
$suppliers = Supplier::select(
|
||||
array('id','name','address','address2','city','state','country','fax', 'phone','email','contact','created_at','updated_at','deleted_at','image','notes')
|
||||
)->withCount('assets')->withCount('licenses')->withCount('accessories');
|
||||
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('accessories as accessories_count');
|
||||
|
||||
|
||||
if ($request->has('search')) {
|
||||
|
@ -115,7 +115,7 @@ class SuppliersController extends Controller
|
|||
public function destroy($id)
|
||||
{
|
||||
$this->authorize('delete', Supplier::class);
|
||||
$supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances','assets', 'licenses')->findOrFail($id);
|
||||
$supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count','assets as assets_count', 'licenses as licenses_count')->findOrFail($id);
|
||||
$this->authorize('delete', $supplier);
|
||||
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class UsersController extends Controller
|
|||
'users.zip',
|
||||
|
||||
])->with('manager', 'groups', 'userloc', 'company', 'department','assets','licenses','accessories','consumables')
|
||||
->withCount('assets','licenses','accessories','consumables');
|
||||
->withCount('assets as assets_count','licenses as licneses_count','accessories as accessories_count','consumables as consumables_count');
|
||||
$users = Company::scopeCompanyables($users);
|
||||
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class BulkAssetModelsController extends Controller
|
|||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||
|
||||
$models = AssetModel::whereIn('id', $models_raw_array)
|
||||
->withCount('assets')
|
||||
->withCount('assets as assets_count')
|
||||
->orderBy('assets_count', 'ASC')
|
||||
->get();
|
||||
|
||||
|
@ -107,7 +107,7 @@ class BulkAssetModelsController extends Controller
|
|||
|
||||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||
|
||||
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets')->get();
|
||||
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
||||
|
||||
$del_error_count = 0;
|
||||
$del_count = 0;
|
||||
|
|
|
@ -154,7 +154,7 @@ class SuppliersController extends Controller
|
|||
public function destroy($supplierId)
|
||||
{
|
||||
$this->authorize('delete', Supplier::class);
|
||||
if (is_null($supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances','assets','licenses')->find($supplierId))) {
|
||||
if (is_null($supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count','assets as assets_count','licenses as licenses_count')->find($supplierId))) {
|
||||
return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.not_found'));
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class ApiCategoriesCest
|
|||
|
||||
$response = json_decode($I->grabResponse(), true);
|
||||
// sample verify
|
||||
$category = App\Models\Category::withCount('assets','accessories','consumables','components','licenses')
|
||||
$category = App\Models\Category::withCount('assets as assets_count','accessories as accessories_count','consumables as consumables_count','components as components_count','licenses as licenses_count')
|
||||
->orderByDesc('id')->take(10)->get()->shuffle()->first();
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new CategoriesTransformer)->transformCategory($category)));
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class ApiCompaniesCest
|
|||
$response = json_decode($I->grabResponse(), true);
|
||||
// dd($response);
|
||||
// sample verify
|
||||
$company = App\Models\Company::withCount('assets','licenses','accessories','consumables','components','users')
|
||||
$company = App\Models\Company::withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count','components as components_count','users as users_count')
|
||||
->orderByDesc('created_at')->take(10)->get()->shuffle()->first();
|
||||
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new CompaniesTransformer)->transformCompany($company)));
|
||||
|
|
|
@ -32,7 +32,7 @@ class ApiLocationsCest
|
|||
$response = json_decode($I->grabResponse(), true);
|
||||
// sample verify
|
||||
$location = App\Models\Location::orderByDesc('created_at')
|
||||
->withCount('assignedAssets', 'assets', 'users')
|
||||
->withCount('assignedAssets as assigned_assets_count', 'assets as assets_count', 'users as users_count')
|
||||
->take(10)->get()->shuffle()->first();
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new LocationsTransformer)->transformLocation($location)));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class ApiAssetModelsCest
|
|||
|
||||
$response = json_decode($I->grabResponse(), true);
|
||||
$assetmodel = App\Models\AssetModel::orderByDesc('created_at')
|
||||
->withCount('assets')->take(10)->get()->shuffle()->first();
|
||||
->withCount('assets as assets_count')->take(10)->get()->shuffle()->first();
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new AssetModelsTransformer)->transformAssetModel($assetmodel)));
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class ApiStatuslabelsCest
|
|||
$response = json_decode($I->grabResponse(), true);
|
||||
// sample verify
|
||||
$statuslabel = App\Models\Statuslabel::orderByDesc('created_at')
|
||||
->withCount('assets')
|
||||
->withCount('assets as assets_count')
|
||||
->take(10)->get()->shuffle()->first();
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new StatuslabelsTransformer)->transformStatuslabel($statuslabel)));
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class ApiUsersCest
|
|||
$response = json_decode($I->grabResponse(), true);
|
||||
// sample verify
|
||||
$user = App\Models\User::orderByDesc('created_at')
|
||||
->withCount('assets', 'licenses', 'accessories', 'consumables')
|
||||
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count')
|
||||
->take(10)->get()->shuffle()->first();
|
||||
$I->seeResponseContainsJson($I->removeTimestamps((new UsersTransformer)->transformUser($user)));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue