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)
{
if (is_null($department = Department::find($id))) {
return redirect()->to(route('departments.index'))->with('error', trans('admin/departments/message.not_found'));
}
$department = Department::findOrFail($id);
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();
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')));
}