Delete account is no longer a GET request
This commit is contained in:
parent
4ae8a45ed3
commit
98d2a1e1fd
3 changed files with 30 additions and 10 deletions
|
@ -47,13 +47,17 @@ class AccountsController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDelete(Request $request, $id)
|
public function deleteView(Request $request, $id)
|
||||||
{
|
{
|
||||||
$user = new UserRepository;
|
try {
|
||||||
$user->delete($id);
|
User::findOrFail($id)->delete();
|
||||||
|
return response(null, 204);
|
||||||
Alert::success('An account has been successfully deleted.')->flash();
|
} catch(\Exception $ex) {
|
||||||
return redirect()->route('admin.accounts');
|
Log::error($ex);
|
||||||
|
return response()->json([
|
||||||
|
'error' => 'An error occured while attempting to delete this user.'
|
||||||
|
], 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postNew(Request $request)
|
public function postNew(Request $request)
|
||||||
|
|
|
@ -55,8 +55,8 @@ class AdminRoutes {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Delete an Account Matching an ID
|
// Delete an Account Matching an ID
|
||||||
$router->get('/delete/{id}', [
|
$router->delete('/view/{id}', [
|
||||||
'uses' => 'Admin\AccountsController@getDelete'
|
'uses' => 'Admin\AccountsController@deleteView'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -61,8 +61,8 @@
|
||||||
<input type="hidden" name="user" value="{{ $user->id }}">
|
<input type="hidden" name="user" value="{{ $user->id }}">
|
||||||
{!! csrf_field() !!}
|
{!! csrf_field() !!}
|
||||||
<input type="submit" value="{{ trans('base.account.update_user') }}" class="btn btn-primary btn-sm">
|
<input type="submit" value="{{ trans('base.account.update_user') }}" class="btn btn-primary btn-sm">
|
||||||
<a href="/admin/accounts/delete/{{ $user->id }}">
|
<a href="#">
|
||||||
<button id="delete" type="button" class="btn btn-sm btn-danger" value="{{ trans('base.account.delete_user') }}">{{ trans('base.account.delete_user') }}</button>
|
<button type="button" class="btn btn-sm btn-danger" data-action="deleteUser" value="{{ trans('base.account.delete_user') }}">{{ trans('base.account.delete_user') }}</button>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
@ -150,6 +150,22 @@ $(document).ready(function(){
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
$('button[data-action="deleteUser"]').click(function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
$.ajax({
|
||||||
|
method: 'DELETE',
|
||||||
|
url: '/admin/accounts/view/{{ $user->id }}',
|
||||||
|
headers: {
|
||||||
|
'X-CSRF-TOKEN': '{{ csrf_token() }}'
|
||||||
|
}
|
||||||
|
}).done(function (data) {
|
||||||
|
alert('Account was successfully deleted from the system.');
|
||||||
|
window.location = '/admin/accounts';
|
||||||
|
}).fail(function (jqXHR) {
|
||||||
|
console.error(jqXHR);
|
||||||
|
alert('An error occured: ' + jqXHR.JSONResponse.error);
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
Loading…
Reference in a new issue