adds user location scope, still needs fine tuning

This commit is contained in:
Godfrey M 2023-11-14 11:49:00 -08:00
parent 442cad69a7
commit 57019e170f
2 changed files with 22 additions and 2 deletions

View file

@ -21,6 +21,7 @@ use Illuminate\Http\Request;
use App\Http\Requests\ImageUploadRequest;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Log;
class UsersController extends Controller
{
@ -185,7 +186,9 @@ class UsersController extends Controller
$users->where('autoassign_licenses', '=', $request->input('autoassign_licenses'));
}
if ($request->filled('search')) {
if ($request->filled('location_id') != '') {
$users = $users->UserLocation($request->input('location_id'), $request->input('search'));
} else {
$users = $users->TextSearch($request->input('search'));
}
@ -530,7 +533,7 @@ class UsersController extends Controller
try {
Storage::disk('public')->delete('avatars/'.$user->avatar);
} catch (\Exception $e) {
\Log::debug($e);
Log::debug($e);
}
}

View file

@ -787,5 +787,22 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this;
}
public function scopeUserLocation($query, $location, $search){
return $query->where('location_id','=', $location)
->where('first_name', 'LIKE', '%' . $search . '%')
->orWhere('email', 'LIKE', '%' . $search . '%')
->orWhere('first_name', 'LIKE', '%' . $search . '%')
->orWhere('permissions', 'LIKE', '%' . $search . '%')
->orWhere('country', 'LIKE', '%' . $search . '%')
->orWhere('phone', 'LIKE', '%' . $search . '%')
->orWhere('jobtitle', 'LIKE', '%' . $search . '%')
->orWhere('employee_num', 'LIKE', '%' . $search . '%')
->orWhere('username', 'LIKE', '%' . $search . '%');
}
}