diff --git a/app/Composers/StatusPageComposer.php b/app/Composers/StatusPageComposer.php index 38d182e6..5c9dd505 100644 --- a/app/Composers/StatusPageComposer.php +++ b/app/Composers/StatusPageComposer.php @@ -35,7 +35,7 @@ class StatusPageComposer 'favicon' => 'favicon-high-alert', ]; - if (Component::where('enabled', true)->notStatus(1)->count() === 0) { + if (Component::enabled()->notStatus(1)->count() === 0) { // If all our components are ok, do we have any non-fixed incidents? $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get(); $incidentCount = $incidents->count(); @@ -48,7 +48,7 @@ class StatusPageComposer ]; } } else { - if (Component::where('enabled', true)->whereIn('status', [2, 3])->count() > 0) { + if (Component::enabled()->whereIn('status', [2, 3])->count() > 0) { $withData['favicon'] = 'favicon-medium-alert'; } } @@ -57,9 +57,9 @@ class StatusPageComposer $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get(); // Component & Component Group lists. - $usedComponentGroups = Component::where('enabled', true)->where('group_id', '>', 0)->groupBy('group_id')->lists('group_id'); + $usedComponentGroups = Component::enabled()->where('group_id', '>', 0)->groupBy('group_id')->lists('group_id'); $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get(); - $ungroupedComponents = Component::where('enabled', true)->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get(); + $ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get(); $view->with($withData) ->withComponentGroups($componentGroups) diff --git a/app/Models/Component.php b/app/Models/Component.php index a12642eb..38375e8a 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -133,6 +133,30 @@ class Component extends Model implements HasPresenter return $query->where('status', '<>', $status); } + /** + * Finds all components which are enabled. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeEnabled(Builder $query) + { + return $query->where('enabled', true); + } + + /** + * Finds all components which are disabled. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeDisabled(Builder $query) + { + return $query->where('enabled', false); + } + /** * Looks up the human readable version of the status. * diff --git a/resources/views/partials/components.blade.php b/resources/views/partials/components.blade.php index d976130c..09c19676 100644 --- a/resources/views/partials/components.blade.php +++ b/resources/views/partials/components.blade.php @@ -1,14 +1,14 @@