Code Duplication    Length = 28-28 lines in 2 locations

src/Http/Controllers/EnrollmentsController.php 2 locations

@@ 70-97 (lines=28) @@
67
     *
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function store(EnrollmentCreateRequest $request)
71
    {
72
        try {
73
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
74
75
            $enrollment = $this->repository->create($request->all());
76
77
            $response = [
78
                'message' => 'Enrollment created.',
79
                'data'    => $enrollment->toArray(),
80
            ];
81
82
            if ($request->wantsJson()) {
83
                return response()->json($response);
84
            }
85
86
            return redirect()->back()->with('message', $response['message']);
87
        } catch (ValidatorException $e) {
88
            if ($request->wantsJson()) {
89
                return response()->json([
90
                    'error'   => true,
91
                    'message' => $e->getMessageBag()
92
                ]);
93
            }
94
95
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
96
        }
97
    }
98
99
100
    /**
@@ 144-171 (lines=28) @@
141
     *
142
     * @return Response
143
     */
144
    public function update(EnrollmentUpdateRequest $request, $id)
145
    {
146
        try {
147
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
148
149
            $enrollment = $this->repository->update($id, $request->all());
150
151
            $response = [
152
                'message' => 'Enrollment updated.',
153
                'data'    => $enrollment->toArray(),
154
            ];
155
156
            if ($request->wantsJson()) {
157
                return response()->json($response);
158
            }
159
160
            return redirect()->back()->with('message', $response['message']);
161
        } catch (ValidatorException $e) {
162
            if ($request->wantsJson()) {
163
                return response()->json([
164
                    'error'   => true,
165
                    'message' => $e->getMessageBag()
166
                ]);
167
            }
168
169
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
170
        }
171
    }
172
173
174
    /**