mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
Adds validator to PATCH request in the API UsersController
This commit is contained in:
parent
95f568b934
commit
e4204a6dd1
|
@ -20,6 +20,7 @@ use Auth;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\ImageUploadRequest;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class UsersController extends Controller
|
||||
{
|
||||
|
@ -452,11 +453,12 @@ class UsersController extends Controller
|
|||
|
||||
// Check if the request has groups passed and has a value
|
||||
if ($request->filled('groups')) {
|
||||
try{
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
} catch (\Exception $exception){
|
||||
return response()->json(Helper::formatStandardApiResponse('error', null, $exception));
|
||||
}
|
||||
$validator = Validator::make($request->input('groups'), [
|
||||
'groups' => 'array',
|
||||
'groups.*' => 'integer',
|
||||
]);
|
||||
|
||||
$user->groups()->sync($request->input('groups'));
|
||||
// The groups field has been passed but it is null, so we should blank it out
|
||||
} elseif ($request->has('groups')) {
|
||||
$user->groups()->sync([]);
|
||||
|
|
Loading…
Reference in a new issue