Skip to content

Commit

Permalink
Add restore to users api endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Delta5 committed Sep 21, 2021
1 parent 9f3b633 commit 59302e1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,26 @@ public function getCurrentUserInfo(Request $request)
{
return (new UsersTransformer)->transformUser($request->user());
}

/**
* Restore a soft-deleted user.
*
* @author [E. Taylor] [<dev@evantaylor.name>]
* @param int $userId
* @since [v6.0.0]
* @return JsonResponse
*/
public function restore($userId = null)
{
// Get asset information
$user = User::withTrashed()->find($userId);
$this->authorize('delete', $user);
if (isset($user->id)) {
// Restore the user
User::withTrashed()->where('id', $userId)->restore();

return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.restored')));
}
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_exists')), 200);
}
}
7 changes: 7 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,13 @@
]
)->name('api.users.uploads');

Route::post('{user}/restore',
[
Api\UsersController::class,
'restore'
]
)->name('api.users.restore');

});

Route::resource('users',
Expand Down

0 comments on commit 59302e1

Please sign in to comment.