mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 13:44:06 -08:00
add withCount to query instead
This commit is contained in:
parent
38a3e36cd6
commit
090466123f
|
@ -320,7 +320,12 @@ class LocationsController extends Controller
|
||||||
$locations_raw_array = $request->input('ids');
|
$locations_raw_array = $request->input('ids');
|
||||||
|
|
||||||
if ((is_array($locations_raw_array)) && (count($locations_raw_array) > 0)) {
|
if ((is_array($locations_raw_array)) && (count($locations_raw_array) > 0)) {
|
||||||
$locations = Location::whereIn('id', $locations_raw_array)->get();
|
$locations = Location::whereIn('id', $locations_raw_array)
|
||||||
|
->withCount('assignedAssets as assigned_assets_count')
|
||||||
|
->withCount('assets as assets_count')
|
||||||
|
->withCount('rtd_assets as rtd_assets_count')
|
||||||
|
->withCount('children as children_count')
|
||||||
|
->withCount('users as users_count')->get();
|
||||||
|
|
||||||
$success_count = 0;
|
$success_count = 0;
|
||||||
$error_count = 0;
|
$error_count = 0;
|
||||||
|
|
|
@ -108,10 +108,10 @@ class Location extends SnipeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
return Gate::allows('delete', $this)
|
return Gate::allows('delete', $this)
|
||||||
&& ($this->assets_count == 0)
|
&& ($this->assets_count === 0)
|
||||||
&& ($this->assigned_assets_count == 0)
|
&& ($this->assigned_assets_count === 0)
|
||||||
&& ($this->children_count == 0)
|
&& ($this->children_count === 0)
|
||||||
&& ($this->users_count == 0);
|
&& ($this->users_count === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue