Skip to content

A free open source IT asset/license management system

Add dynamic scope for prettier multiple column search

Marcus Moore9078d4c71cdf
diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php
index 4165dc98b9..63ee0f5b23 100644
--- a/app/Models/Traits/Searchable.php
+++ b/app/Models/Traits/Searchable.php
@@ -282,4 +282,9 @@ trait Searchable
// Default to MySQL's concatenation method
return 'CONCAT(' . implode('," ",', $columns) . ') LIKE ?';
}
+
+ public function scopeOrWhereMultipleColumns($query, array $columns, $term)
+ {
+ return $query->orWhereRaw($this->buildMultipleColumnSearch($columns), ["%{$term}%"]);
+ }
}