mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 05:31:24 +00:00
Scope users listing and search to current company (#607)
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:
committed by
GitHub
parent
3d871604ae
commit
7d9fdb79cc
@@ -25,7 +25,8 @@ class SearchController extends Controller
|
||||
->paginate(10);
|
||||
|
||||
if ($user->isOwner()) {
|
||||
$users = User::applyFilters($request->only(['search']))
|
||||
$users = User::whereCompany()
|
||||
->applyFilters($request->only(['search']))
|
||||
->latest()
|
||||
->paginate(10);
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
]]);
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,13 @@ class User extends Authenticatable implements HasMedia
|
||||
return $query->where('email', 'LIKE', '%'.$email.'%');
|
||||
}
|
||||
|
||||
public function scopeWhereCompany($query)
|
||||
{
|
||||
return $query->whereHas('companies', function ($q) {
|
||||
$q->where('company_id', request()->header('company'));
|
||||
});
|
||||
}
|
||||
|
||||
public function scopePaginateData($query, $limit)
|
||||
{
|
||||
if ($limit == 'all') {
|
||||
|
||||
Reference in New Issue
Block a user