Fixes #3860 - return JSON instead of redirect in API delete dept call

This commit is contained in:
snipe 2017-08-22 14:15:13 -07:00
parent 8c5312b931
commit eaaea303f4

View file

@ -99,16 +99,14 @@ class DepartmentsController extends Controller
*/ */
public function destroy($id) public function destroy($id)
{ {
if (is_null($department = Department::find($id))) { $department = Department::findOrFail($id);
return redirect()->to(route('departments.index'))->with('error', trans('admin/departments/message.not_found'));
}
if ($department->users->count() > 0) { if ($department->users->count() > 0) {
return redirect()->to(route('departments.index'))->with('error', trans('admin/departments/message.assoc_users')); return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/departments/message.assoc_users')));
} }
$department->delete(); $department->delete();
return redirect()->to(route('departments.index'))->with('success', trans('admin/departments/message.delete.success')); return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/departments/message.delete.success')));
} }