Skip to content

Commit

Permalink
added active local scope
Browse files Browse the repository at this point in the history
  • Loading branch information
nasirkhan authored Sep 6, 2024
1 parent 2c6ea92 commit a66f9e9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Backend/BackendBaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
11 changes: 11 additions & 0 deletions app/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a66f9e9

Please sign in to comment.