From eb3aa99e4f808e7e377c73607e9b84c34292dd30 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 23 May 2017 02:45:51 -0700 Subject: [PATCH] Added destroy method to dept --- .../Controllers/Api/DepartmentsController.php | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/Http/Controllers/Api/DepartmentsController.php b/app/Http/Controllers/Api/DepartmentsController.php index 0f324d9781..f4eeec53c5 100644 --- a/app/Http/Controllers/Api/DepartmentsController.php +++ b/app/Http/Controllers/Api/DepartmentsController.php @@ -81,4 +81,30 @@ class DepartmentsController extends Controller $department = Department::findOrFail($id); return (new DepartmentsTransformer)->transformDepartment($department); } + + + + /** + * Validates and deletes selected location. + * + * @author [A. Gianotto] [] + * @param int $locationId + * @since [v1.0] + * @return \Illuminate\Http\RedirectResponse + */ + 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')); + } + + if ($department->users->count() > 0) { + return redirect()->to(route('departments.index'))->with('error', trans('admin/departments/message.assoc_users')); + } + + $department->delete(); + return redirect()->to(route('departments.index'))->with('success', trans('admin/departments/message.delete.success')); + + } + }