Skip to content

A free open source IT asset/license management system

Removed stupid count method

sniped1de34394e5b
diff --git a/app/Http/Controllers/StatuslabelsController.php b/app/Http/Controllers/StatuslabelsController.php
index dc46f283b0..0b075d6e79 100755
--- a/app/Http/Controllers/StatuslabelsController.php
+++ b/app/Http/Controllers/StatuslabelsController.php
@@ -200,17 +200,15 @@ class StatuslabelsController extends Controller
{
// Check if the Statuslabel exists
if (is_null($statuslabel = Statuslabel::find($statuslabelId))) {
- // Redirect to the blogs management page
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.not_found'));
}
-
- if ($statuslabel->has_assets() == 0) {
+ // Check that there are no assets associated
+ if ($statuslabel->assets()->count() == 0) {
$statuslabel->delete();
- // Redirect to the statuslabels management page
return redirect()->route('statuslabels.index')->with('success', trans('admin/statuslabels/message.delete.success'));
}
- // Redirect to the asset management page
+
return redirect()->route('statuslabels.index')->with('error', trans('admin/statuslabels/message.assoc_assets'));
}
diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php
index 2bb92dec41..c650521ca0 100755
--- a/app/Models/Statuslabel.php
+++ b/app/Models/Statuslabel.php
@@ -29,16 +29,6 @@ class Statuslabel extends SnipeModel
protected $fillable = ['name', 'deployable', 'pending', 'archived'];
- /**
- * Show count of assets with status label
- *
- * @todo Remove this. It's dumb.
- * @return \Illuminate\Support\Collection
- */
- public function has_assets()
- {
- return $this->hasMany('\App\Models\Asset', 'status_id')->count();
- }
/**
* Get assets with associated status label
@@ -64,6 +54,27 @@ class Statuslabel extends SnipeModel
}
}
+ public function scopePending()
+ {
+ return $this->where('pending', '=', 1)
+ ->where('archived', '=', 0)
+ ->where('deployable', '=', 0);
+ }
+
+ public function scopeArchived()
+ {
+ return $this->where('pending', '=', 0)
+ ->where('archived', '=', 1)
+ ->where('deployable', '=', 0);
+ }
+
+ public function scopeDeployable()
+ {
+ return $this->where('pending', '=', 0)
+ ->where('archived', '=', 0)
+ ->where('deployable', '=', 1);
+ }
+
public static function getStatuslabelTypesForDB($type)
{