Scope users listing and search to current company

Add scopeWhereCompany() to User model using whereHas through the
user_company pivot table. Apply it in UsersController::index() and
SearchController so users only see members of their current company.

Previously, the users page showed ALL users across all companies.

Ref #574
This commit is contained in:
Darko Gjorgjijoski
2026-04-03 14:27:45 +02:00
parent 1adebe85b9
commit 36e7c88e46
3 changed files with 12 additions and 3 deletions

View File

@@ -25,14 +25,15 @@ class UsersController extends Controller
$user = $request->user();
$users = User::applyFilters($request->all())
$users = User::whereCompany()
->applyFilters($request->all())
->where('id', '<>', $user->id)
->latest()
->paginate($limit);
return UserResource::collection($users)
->additional(['meta' => [
'user_total_count' => User::count(),
'user_total_count' => User::whereCompany()->count(),
]]);
}