Code Duplication    Length = 31-33 lines in 2 locations

src/Http/Controllers/AttendancesController.php 2 locations

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