Added destroy method to dept

This commit is contained in:
snipe 2017-05-23 02:45:51 -07:00
parent a7592de304
commit eb3aa99e4f

View file

@ -81,4 +81,30 @@ class DepartmentsController extends Controller
$department = Department::findOrFail($id); $department = Department::findOrFail($id);
return (new DepartmentsTransformer)->transformDepartment($department); return (new DepartmentsTransformer)->transformDepartment($department);
} }
/**
* Validates and deletes selected location.
*
* @author [A. Gianotto] [<snipe@snipe.net>]
* @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'));
}
} }