Skip to content

Commit

Permalink
Fixed scope for users
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe committed Nov 3, 2015
1 parent 5bed048 commit 0745ec1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/controllers/admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,8 @@ public function getDatatable($status = null)
$sort = e(Input::get('sort'));
}

$users = User::select('users.*')->with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'sentryThrottle', 'groups', 'userloc');
$users = User::select(array('users.id','users.email','users.username','users.location_id','users.manager_id','users.first_name','users.last_name','users.created_at'))
->with('assets', 'accessories', 'consumables', 'licenses', 'manager', 'sentryThrottle', 'groups', 'userloc');

switch ($status) {
case 'deleted':
Expand Down
12 changes: 6 additions & 6 deletions app/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ public function scopeTextsearch($query, $search)
{

return $query->where(function($query) use ($search) {
$query->where('first_name', 'LIKE', "%$search%")
->orWhere('last_name', 'LIKE', "%$search%")
->orWhere('email', 'LIKE', "%$search%")
->orWhere('username', 'LIKE', "%$search%")
->orWhere('notes', 'LIKE', "%$search%")
$query->where('users.first_name', 'LIKE', "%$search%")
->orWhere('users.last_name', 'LIKE', "%$search%")
->orWhere('users.email', 'LIKE', "%$search%")
->orWhere('users.username', 'LIKE', "%$search%")
->orWhere('users.notes', 'LIKE', "%$search%")
->orWhere(function($query) use ($search) {
$query->whereHas('userloc', function($query) use ($search) {
$query->where('name','LIKE','%'.$search.'%');
Expand All @@ -225,7 +225,7 @@ public function scopeTextsearch($query, $search)

// Ugly, ugly code because Laravel sucks at self-joins
->orWhere(function($query) use ($search) {
$query->whereRaw("manager_id IN (select id from users where first_name LIKE '%".$search."%' OR last_name LIKE '%".$search."%') ");
$query->whereRaw("users.manager_id IN (select id from users where first_name LIKE '%".$search."%' OR last_name LIKE '%".$search."%') ");
});
});

Expand Down

0 comments on commit 0745ec1

Please sign in to comment.