mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-13 06:47:46 -08:00
Adjust validator to only receive valid groups id's
This commit is contained in:
parent
e4204a6dd1
commit
e7b3daa80c
|
@ -453,11 +453,14 @@ class UsersController extends Controller
|
||||||
|
|
||||||
// Check if the request has groups passed and has a value
|
// Check if the request has groups passed and has a value
|
||||||
if ($request->filled('groups')) {
|
if ($request->filled('groups')) {
|
||||||
$validator = Validator::make($request->input('groups'), [
|
$validator = Validator::make($request->all(), [
|
||||||
'groups' => 'array',
|
'groups' => 'integer|exists:permission_groups,id',
|
||||||
'groups.*' => 'integer',
|
'groups.*' => 'integer|exists:permission_groups,id',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($validator->fails()){
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $user->getErrors()));
|
||||||
|
}
|
||||||
$user->groups()->sync($request->input('groups'));
|
$user->groups()->sync($request->input('groups'));
|
||||||
// The groups field has been passed but it is null, so we should blank it out
|
// The groups field has been passed but it is null, so we should blank it out
|
||||||
} elseif ($request->has('groups')) {
|
} elseif ($request->has('groups')) {
|
||||||
|
|
Loading…
Reference in a new issue