Code Duplication    Length = 37-39 lines in 2 locations

src/Http/Controllers/LessonsController.php 2 locations

@@ 68-104 (lines=37) @@
65
     *
66
     * @return \Illuminate\Http\Response
67
     */
68
    public function store(LessonCreateRequest $request)
69
    {
70
        try {
71
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
72
73
            $lesson = $this->repository->create($request->all());
74
75
            if ($request->has('user_id')) {
76
                $user_id = $request->input('user_id');
77
                $user = \App\User::find($user_id);
78
                $lesson->users()->save($user);
79
            }
80
81
            $response = [
82
                'message' => 'Lesson created.',
83
                'data'    => $lesson->toArray(),
84
            ];
85
86
            if ($request->wantsJson()) {
87
                return response()->json($response);
88
            }
89
90
            return redirect()->back()->with('message', $response['message']);
91
        } catch (ValidatorException $e) {
92
            if ($request->wantsJson()) {
93
                return response()->json([
94
                    'error'   => true,
95
                    'message' => $e->getMessageBag()
96
                ]);
97
            }
98
99
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
100
        }
101
    }
102
103
104
    /**
105
     * Display the specified resource.
106
     *
107
     * @param  int $id
@@ 148-186 (lines=39) @@
145
     *
146
     * @return Response
147
     */
148
    public function update(LessonUpdateRequest $request, $id)
149
    {
150
        try {
151
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
152
153
            $lesson = $this->repository->update($request->all(), $id);
154
155
            if ($request->has('user_id')) {
156
                $user_id = $request->input('user_id');
157
                $user = \App\User::find($user_id);
158
                $lesson->users()->save($user);
159
            }
160
161
            $response = [
162
                'message' => 'Lesson updated.',
163
                'data'    => $lesson->toArray(),
164
            ];
165
166
            if ($request->wantsJson()) {
167
                return response()->json($response);
168
            }
169
170
            return redirect()->back()->with('message', $response['message']);
171
        } catch (ValidatorException $e) {
172
            if ($request->wantsJson()) {
173
                return response()->json([
174
                    'error'   => true,
175
                    'message' => $e->getMessageBag()
176
                ]);
177
            }
178
179
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
180
        }
181
    }
182
183
184
    /**
185
     * Remove the specified resource from storage.
186
     *
187
     * @param  int $id
188
     *
189
     * @return \Illuminate\Http\Response