mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -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 Illuminate\Http\Request;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class UsersController extends Controller
|
class UsersController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -452,11 +453,12 @@ 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')) {
|
||||||
try{
|
$validator = Validator::make($request->input('groups'), [
|
||||||
$user->groups()->sync($request->input('groups'));
|
'groups' => 'array',
|
||||||
} catch (\Exception $exception){
|
'groups.*' => 'integer',
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $exception));
|
]);
|
||||||
}
|
|
||||||
|
$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')) {
|
||||||
$user->groups()->sync([]);
|
$user->groups()->sync([]);
|
||||||
|
|
Loading…
Reference in a new issue