mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-09 14:34:47 +00:00
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:
@@ -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(),
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user