diff --git a/app/Models/Consumable.php b/app/Models/Consumable.php index 23487c5ba..7f61c895f 100644 --- a/app/Models/Consumable.php +++ b/app/Models/Consumable.php @@ -156,6 +156,10 @@ class Consumable extends SnipeModel return $this->belongsToMany('\App\Models\User', 'consumables_users', 'consumable_id', 'assigned_to')->count(); } + public function checkin_email() + { + return $this->category->checkin_email; + } public function requireAcceptance() { diff --git a/app/Models/License.php b/app/Models/License.php index 559b48ebe..9685b4b8f 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -228,7 +228,7 @@ class License extends Depreciable public function checkin_email() { - return $this->model->category->checkin_email; + return $this->category->checkin_email; } public function requireAcceptance() diff --git a/app/Models/Traits/Searchable.php b/app/Models/Traits/Searchable.php index b6438b824..96e88f7cb 100644 --- a/app/Models/Traits/Searchable.php +++ b/app/Models/Traits/Searchable.php @@ -53,7 +53,7 @@ trait Searchable { * @param string $search The search term * @return array An array of search terms */ - private function prepeareSearchTerms(string $search) { + private function prepeareSearchTerms($search) { return explode(' OR ', $search); } @@ -68,6 +68,8 @@ trait Searchable { $table = $this->getTable(); + $firstConditionAdded = false; + foreach($this->getSearchableAttributes() as $column) { foreach($terms as $term) { @@ -80,6 +82,19 @@ trait Searchable { continue; } + /** + * We need to form the query properly, starting with a "where", + * otherwise the generated select is wrong. + * + * @todo This does the job, but is inelegant and fragile + */ + if (!$firstConditionAdded) { + $query = $query->where($table . '.' . $column, 'LIKE', '%'.$term.'%'); + + $firstConditionAdded = true; + continue; + } + $query = $query->orWhere($table . '.' . $column, 'LIKE', '%'.$term.'%'); } }