Use new dynamic scope where possible

This commit is contained in:
Marcus Moore 2023-05-23 13:38:50 -07:00
parent 054d71aedc
commit b2b6f0cf96
No known key found for this signature in database
2 changed files with 16 additions and 28 deletions

View file

@ -947,13 +947,10 @@ class Asset extends Depreciable
->orWhere('assets_users.first_name', 'LIKE', '%'.$term.'%') ->orWhere('assets_users.first_name', 'LIKE', '%'.$term.'%')
->orWhere('assets_users.last_name', 'LIKE', '%'.$term.'%') ->orWhere('assets_users.last_name', 'LIKE', '%'.$term.'%')
->orWhere('assets_users.username', 'LIKE', '%'.$term.'%') ->orWhere('assets_users.username', 'LIKE', '%'.$term.'%')
->orWhereRaw( ->orWhereMultipleColumns([
$this->buildMultipleColumnSearch([ DB::getTablePrefix() . 'assets_users.first_name',
DB::getTablePrefix().'assets_users.first_name', DB::getTablePrefix() . 'assets_users.last_name',
DB::getTablePrefix().'assets_users.last_name', ], $term);
]),
["%{$term}%"]
);
} }
/** /**
@ -1348,13 +1345,10 @@ class Asset extends Depreciable
})->orWhere(function ($query) use ($search) { })->orWhere(function ($query) use ($search) {
$query->where('assets_users.first_name', 'LIKE', '%'.$search.'%') $query->where('assets_users.first_name', 'LIKE', '%'.$search.'%')
->orWhere('assets_users.last_name', 'LIKE', '%'.$search.'%') ->orWhere('assets_users.last_name', 'LIKE', '%'.$search.'%')
->orWhereRaw( ->orWhereMultipleColumns([
$this->buildMultipleColumnSearch([ DB::getTablePrefix() . 'assets_users.first_name',
DB::getTablePrefix().'assets_users.first_name', DB::getTablePrefix() . 'assets_users.last_name',
DB::getTablePrefix().'assets_users.last_name', ], $search)
]),
["%{$search}%"]
)
->orWhere('assets_users.username', 'LIKE', '%'.$search.'%') ->orWhere('assets_users.username', 'LIKE', '%'.$search.'%')
->orWhere('assets_locations.name', 'LIKE', '%'.$search.'%') ->orWhere('assets_locations.name', 'LIKE', '%'.$search.'%')
->orWhere('assigned_assets.name', 'LIKE', '%'.$search.'%'); ->orWhere('assigned_assets.name', 'LIKE', '%'.$search.'%');

View file

@ -646,13 +646,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
{ {
return $query->where('first_name', 'LIKE', '%' . $search . '%') return $query->where('first_name', 'LIKE', '%' . $search . '%')
->orWhere('last_name', 'LIKE', '%' . $search . '%') ->orWhere('last_name', 'LIKE', '%' . $search . '%')
->orWhereRaw( ->orWhereMultipleColumns([
$this->buildMultipleColumnSearch([ DB::getTablePrefix() . 'users.first_name',
DB::getTablePrefix() . 'users.first_name', DB::getTablePrefix() . 'users.last_name',
DB::getTablePrefix() . 'users.last_name', ], $search);
]),
["%{$search}%"]
);
} }
/** /**
@ -665,13 +662,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
public function advancedTextSearch(Builder $query, array $terms) { public function advancedTextSearch(Builder $query, array $terms) {
foreach($terms as $term) { foreach($terms as $term) {
$query = $query->orWhereRaw( $query->orWhereMultipleColumns([
$this->buildMultipleColumnSearch([ DB::getTablePrefix() . 'users.first_name',
DB::getTablePrefix() . 'users.first_name', DB::getTablePrefix() . 'users.last_name',
DB::getTablePrefix() . 'users.last_name', ], $term);
]),
["%{$term}%"]
);
} }
return $query; return $query;