From a66f9e91b9e6bfa1866f02f6c434feef89514aa9 Mon Sep 17 00:00:00 2001 From: Nasir Khan Saikat Date: Sat, 7 Sep 2024 01:40:21 +0600 Subject: [PATCH] added active local scope --- .../Controllers/Backend/BackendBaseController.php | 2 +- app/Models/BaseModel.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Backend/BackendBaseController.php b/app/Http/Controllers/Backend/BackendBaseController.php index e2e909cae..8aaa9ab92 100644 --- a/app/Http/Controllers/Backend/BackendBaseController.php +++ b/app/Http/Controllers/Backend/BackendBaseController.php @@ -91,7 +91,7 @@ public function index_list(Request $request) return response()->json([]); } - $query_data = $module_model::where('name', 'LIKE', "%{$term}%")->orWhere('slug', 'LIKE', "%{$term}%")->limit(7)->get(); + $query_data = $module_model::where('name', 'LIKE', "%{$term}%")->orWhere('slug', 'LIKE', "%{$term}%")->active()->limit(7)->get(); $$module_name = []; diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index fc0c87368..e2f87b35d 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -227,4 +227,15 @@ public function setMetaOgImageAttribute($value) } } } + + /** + * Scope a query to only include active models. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return void + */ + public function scopeActive(Builder $query): void + { + $query->where('status', '=', 1); + } }