search by title and slug

This commit is contained in:
Kerim 2022-12-31 15:21:39 +05:00
parent 8a7e53902e
commit 8477728363
2 changed files with 10 additions and 7 deletions

View File

@ -14,8 +14,8 @@ scopes:
label: Post Title
type: text
modelClass: RainLab\Blog\Models\Post
scope: FilterId
scope: FilterName
category:
# Filter name

View File

@ -536,14 +536,17 @@ class Post extends Model
{
return $query->where('id', $id);
}
public function scopeFilterName($query, $q)
public function scopeFilterName($query, $name)
{
return $query = where('title','LIKE','%'.$q.'%')
->orWhere('slug','LIKE','%'.$q.'%');
return $query->where('title','LIKE','%'.$name.'%')->orWhere('slug','LIKE','%'.$name.'%');
}
// public function scopeFilterName($query, $name)
// {
// return $query = where('title','LIKE','%'.$name.'%');
// }
public function scopeFilterLocale($query, array $types) {
foreach ($types as $type) {
switch ($type) {