app/Http/Controllers/Api/Admin/UserController.php
/**
     * Update the specified resource in storage.
     *
     * @param  UpdateRequest  $request
     * @param  string  $uuid
     * @return JsonResponse
     * @throws Throwable
     */
Update the specified resource in storage.
@param  UpdateRequest  $request
@param  string  $uuid
@return JsonResponse
@throws Throwable
Update the specified resource in storage . @param UpdateRequest $request @param string $uuid @return JsonResponse @throws Throwable
public function update(UpdateRequest $request, string $uuid): JsonResponse
    {
        $this->authorize('update', User::class);
        if ($request->has('action') && $request->get('action') === 'removeRole') {
            return $this->removeRole($request);
        }
        $user = User::whereUuid($uuid)->first();
        DB::transaction(function () use ($user, $request) {
            $user->setName($request->get('name'))
                ->setEmail($request->get('email'))
                ->save();
            activity('admin')
                ->performedOn($user)
                ->causedBy(auth()->user())
                ->withProperties($request->all())
                ->log('updated user');
            if ($request->get('admin') !== null) {
                DB::transaction(function () use ($user, $request) {
                    $admin = Admin::firstOrCreate(['user_id' => $user->id, 'role' => $request->get('admin')['role']]);
                    $admin = Admin::find($admin->id);
                    activity('admin')
                        ->performedOn($admin)
                        ->causedBy(auth()->user())
                        ->withProperties($request->all())
                        ->log('adding role to user');
                });
            }
        });
        return response()->json(['message' => __('User has been updated.')]);
    }
public function update ( UpdateRequest $ request , string $ uuid ) : JsonResponse { $ this -> authorize ( 'update' , User :: class ) ; if ( $ request -> has ( 'action' ) && $ request -> get ( 'action' ) === 'removeRole' ) { return $ this -> removeRole ( $ request ) ; } $ user = User :: whereUuid ( $ uuid ) -> first ( ) ; DB :: transaction ( function ( ) use ( $ user , $ request ) { $ user -> setName ( $ request -> get ( 'name' ) ) -> setEmail ( $ request -> get ( 'email' ) ) -> save ( ) ; activity ( 'admin' ) -> performedOn ( $ user ) -> causedBy ( auth ( ) -> user ( ) ) -> withProperties ( $ request -> all ( ) ) -> log ( 'updated user' ) ; if ( $ request -> get ( 'admin' ) !== null ) { DB :: transaction ( function ( ) use ( $ user , $ request ) { $ admin = Admin :: firstOrCreate ( [ 'user_id' => $ user -> id , 'role' => $ request -> get ( 'admin' ) [ 'role' ] ] ) ; $ admin = Admin :: find ( $ admin -> id ) ; activity ( 'admin' ) -> performedOn ( $ admin ) -> causedBy ( auth ( ) -> user ( ) ) -> withProperties ( $ request -> all ( ) ) -> log ( 'adding role to user' ) ; } ) ; } } ) ; return response ( ) -> json ( [ 'message' => __ ( 'User has been updated.' ) ] ) ; }
Update the specified resource in storage.
Update the specified resource in storage .