Update withCounts because Laravel 5.5 :(

This commit is contained in:
snipe 2018-07-24 22:40:05 -07:00
parent e6dd90e055
commit 0714ac4248
23 changed files with 32 additions and 31 deletions

View file

@ -39,7 +39,7 @@ class SyncAssetCounters extends Command
public function handle() public function handle()
{ {
$start = microtime(true); $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(); ->withTrashed()->get();
if ($assets) { if ($assets) {

View file

@ -281,9 +281,9 @@ class Helper
*/ */
public static function checkLowInventory() public static function checkLowInventory()
{ {
$consumables = Consumable::withCount('consumableAssignments')->whereNotNull('min_amt')->get(); $consumables = Consumable::withCount('consumableAssignments as consumable_assignments_count')->whereNotNull('min_amt')->get();
$accessories = Accessory::withCount('users')->whereNotNull('min_amt')->get(); $accessories = Accessory::withCount('users as users_count')->whereNotNull('min_amt')->get();
$components = Component::withCount('assets')->whereNotNull('min_amt')->get(); $components = Component::withCount('assets as assets_count')->whereNotNull('min_amt')->get();
$avail_consumables = 0; $avail_consumables = 0;
$items_array = array(); $items_array = array();

View file

@ -48,7 +48,7 @@ class AssetModelsController extends Controller
'models.updated_at', 'models.updated_at',
]) ])
->with('category','depreciation', 'manufacturer','fieldset') ->with('category','depreciation', 'manufacturer','fieldset')
->withCount('assets'); ->withCount('assets as assets_count');
@ -114,7 +114,7 @@ class AssetModelsController extends Controller
public function show($id) public function show($id)
{ {
$this->authorize('view', AssetModel::class); $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); return (new AssetModelsTransformer)->transformAssetModel($assetmodel);
} }

View file

@ -325,7 +325,8 @@ class AssetsController extends Controller
*/ */
public function show($id) 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); $this->authorize('view', $asset);
return (new AssetsTransformer)->transformAsset($asset); return (new AssetsTransformer)->transformAsset($asset);
} }

View file

@ -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']; $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']) $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')) { if ($request->has('search')) {
$categories = $categories->TextSearch($request->input('search')); $categories = $categories->TextSearch($request->input('search'));

View file

@ -35,7 +35,7 @@ class CompaniesController extends Controller
'components_count', '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')) { if ($request->has('search')) {
$companies->TextSearch($request->input('search')); $companies->TextSearch($request->input('search'));

View file

@ -43,7 +43,7 @@ class CustomFieldsetsController extends Controller
public function index() public function index()
{ {
$this->authorize('index', CustomFieldset::class); $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()); return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count());
} }

View file

@ -33,7 +33,7 @@ class DepartmentsController extends Controller
'departments.created_at', 'departments.created_at',
'departments.updated_at', 'departments.updated_at',
'departments.image' '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')) { if ($request->has('search')) {
$departments = $departments->TextSearch($request->input('search')); $departments = $departments->TextSearch($request->input('search'));

View file

@ -22,7 +22,7 @@ class GroupsController extends Controller
$this->authorize('view', Group::class); $this->authorize('view', Group::class);
$allowed_columns = ['id','name','created_at', 'users_count']; $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')) { if ($request->has('search')) {
$groups = $groups->TextSearch($request->input('search')); $groups = $groups->TextSearch($request->input('search'));

View file

@ -25,7 +25,7 @@ class LicensesController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$this->authorize('view', License::class); $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')) { if ($request->has('company_id')) {

View file

@ -41,9 +41,9 @@ class LocationsController extends Controller
'locations.updated_at', 'locations.updated_at',
'locations.image', 'locations.image',
'locations.currency' 'locations.currency'
])->withCount('assignedAssets') ])->withCount('assignedAssets as assigned_assets_count')
->withCount('assets') ->withCount('assets as assets_count')
->withCount('users'); ->withCount('users as users_count');
if ($request->has('search')) { if ($request->has('search')) {
$locations = $locations->TextSearch($request->input('search')); $locations = $locations->TextSearch($request->input('search'));

View file

@ -26,7 +26,7 @@ class ManufacturersController extends Controller
$manufacturers = Manufacturer::select( $manufacturers = Manufacturer::select(
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'deleted_at') 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') { if ($request->input('deleted')=='true') {
$manufacturers->onlyTrashed(); $manufacturers->onlyTrashed();

View file

@ -24,7 +24,7 @@ class StatuslabelsController extends Controller
$this->authorize('view', Statuslabel::class); $this->authorize('view', Statuslabel::class);
$allowed_columns = ['id','name','created_at', 'assets_count','color','default_label']; $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')) { if ($request->has('search')) {
$statuslabels = $statuslabels->TextSearch($request->input('search')); $statuslabels = $statuslabels->TextSearch($request->input('search'));
@ -162,7 +162,7 @@ class StatuslabelsController extends Controller
{ {
$this->authorize('view', Statuslabel::class); $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=[]; $labels=[];
$points=[]; $points=[];

View file

@ -26,7 +26,7 @@ class SuppliersController extends Controller
$suppliers = Supplier::select( $suppliers = Supplier::select(
array('id','name','address','address2','city','state','country','fax', 'phone','email','contact','created_at','updated_at','deleted_at','image','notes') 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')) { if ($request->has('search')) {
@ -115,7 +115,7 @@ class SuppliersController extends Controller
public function destroy($id) public function destroy($id)
{ {
$this->authorize('delete', Supplier::class); $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); $this->authorize('delete', $supplier);

View file

@ -56,7 +56,7 @@ class UsersController extends Controller
'users.zip', 'users.zip',
])->with('manager', 'groups', 'userloc', 'company', 'department','assets','licenses','accessories','consumables') ])->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); $users = Company::scopeCompanyables($users);

View file

@ -26,7 +26,7 @@ class BulkAssetModelsController extends Controller
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) { if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
$models = AssetModel::whereIn('id', $models_raw_array) $models = AssetModel::whereIn('id', $models_raw_array)
->withCount('assets') ->withCount('assets as assets_count')
->orderBy('assets_count', 'ASC') ->orderBy('assets_count', 'ASC')
->get(); ->get();
@ -107,7 +107,7 @@ class BulkAssetModelsController extends Controller
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) { 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_error_count = 0;
$del_count = 0; $del_count = 0;

View file

@ -154,7 +154,7 @@ class SuppliersController extends Controller
public function destroy($supplierId) public function destroy($supplierId)
{ {
$this->authorize('delete', Supplier::class); $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')); return redirect()->route('suppliers.index')->with('error', trans('admin/suppliers/message.not_found'));
} }

View file

@ -31,7 +31,7 @@ class ApiCategoriesCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
// sample verify // 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(); ->orderByDesc('id')->take(10)->get()->shuffle()->first();
$I->seeResponseContainsJson($I->removeTimestamps((new CategoriesTransformer)->transformCategory($category))); $I->seeResponseContainsJson($I->removeTimestamps((new CategoriesTransformer)->transformCategory($category)));
} }

View file

@ -32,7 +32,7 @@ class ApiCompaniesCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
// dd($response); // dd($response);
// sample verify // 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(); ->orderByDesc('created_at')->take(10)->get()->shuffle()->first();
$I->seeResponseContainsJson($I->removeTimestamps((new CompaniesTransformer)->transformCompany($company))); $I->seeResponseContainsJson($I->removeTimestamps((new CompaniesTransformer)->transformCompany($company)));

View file

@ -32,7 +32,7 @@ class ApiLocationsCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
// sample verify // sample verify
$location = App\Models\Location::orderByDesc('created_at') $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(); ->take(10)->get()->shuffle()->first();
$I->seeResponseContainsJson($I->removeTimestamps((new LocationsTransformer)->transformLocation($location))); $I->seeResponseContainsJson($I->removeTimestamps((new LocationsTransformer)->transformLocation($location)));
} }

View file

@ -31,7 +31,7 @@ class ApiAssetModelsCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
$assetmodel = App\Models\AssetModel::orderByDesc('created_at') $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))); $I->seeResponseContainsJson($I->removeTimestamps((new AssetModelsTransformer)->transformAssetModel($assetmodel)));
} }

View file

@ -32,7 +32,7 @@ class ApiStatuslabelsCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
// sample verify // sample verify
$statuslabel = App\Models\Statuslabel::orderByDesc('created_at') $statuslabel = App\Models\Statuslabel::orderByDesc('created_at')
->withCount('assets') ->withCount('assets as assets_count')
->take(10)->get()->shuffle()->first(); ->take(10)->get()->shuffle()->first();
$I->seeResponseContainsJson($I->removeTimestamps((new StatuslabelsTransformer)->transformStatuslabel($statuslabel))); $I->seeResponseContainsJson($I->removeTimestamps((new StatuslabelsTransformer)->transformStatuslabel($statuslabel)));
} }

View file

@ -31,7 +31,7 @@ class ApiUsersCest
$response = json_decode($I->grabResponse(), true); $response = json_decode($I->grabResponse(), true);
// sample verify // sample verify
$user = App\Models\User::orderByDesc('created_at') $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(); ->take(10)->get()->shuffle()->first();
$I->seeResponseContainsJson($I->removeTimestamps((new UsersTransformer)->transformUser($user))); $I->seeResponseContainsJson($I->removeTimestamps((new UsersTransformer)->transformUser($user)));
} }