Code Duplication    Length = 173-183 lines in 2 locations

src/Http/Controllers/AttendancesController.php 1 location

@@ 13-185 (lines=173) @@
10
use Scool\Timetables\Repositories\AttendanceRepository;
11
use Scool\Timetables\Validators\AttendanceValidator;
12
13
class AttendancesController extends Controller
14
{
15
16
    /**
17
     * @var AttendanceRepository
18
     */
19
    protected $repository;
20
21
    /**
22
     * @var AttendanceValidator
23
     */
24
    protected $validator;
25
26
    public function __construct(AttendanceRepository $repository, AttendanceValidator $validator)
27
    {
28
        $this->repository = $repository;
29
        $this->validator  = $validator;
30
    }
31
32
33
    /**
34
     * Display a listing of the resource.
35
     *
36
     * @return \Illuminate\Http\Response
37
     */
38
    public function index()
39
    {
40
        $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
41
        $attendances = $this->repository->all();
42
43
        if (request()->wantsJson()) {
44
            return response()->json([
45
                'data' => $attendances,
46
            ]);
47
        }
48
49
        return view('attendances.index', compact('attendances'));
50
    }
51
52
    //TODO : create
53
54
    /**
55
     * Store a newly created resource in storage.
56
     *
57
     * @param  AttendanceCreateRequest $request
58
     *
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function store(AttendanceCreateRequest $request)
62
    {
63
        try {
64
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
65
66
            $attendance = $this->repository->create($request->all());
67
68
            $response = [
69
                'message' => 'Attendance created.',
70
                'data'    => $attendance->toArray(),
71
            ];
72
73
            if ($request->wantsJson()) {
74
                return response()->json($response);
75
            }
76
77
            return redirect()->back()->with('message', $response['message']);
78
        } catch (ValidatorException $e) {
79
            if ($request->wantsJson()) {
80
                return response()->json([
81
                    'error'   => true,
82
                    'message' => $e->getMessageBag()
83
                ]);
84
            }
85
86
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
87
        }
88
    }
89
90
91
    /**
92
     * Display the specified resource.
93
     *
94
     * @param  int $id
95
     *
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function show($id)
99
    {
100
        $attendance = $this->repository->find($id);
101
102
        if (request()->wantsJson()) {
103
            return response()->json([
104
                'data' => $attendance,
105
            ]);
106
        }
107
108
        return view('attendances.show', compact('attendance'));
109
    }
110
111
112
    /**
113
     * Show the form for editing the specified resource.
114
     *
115
     * @param  int $id
116
     *
117
     * @return \Illuminate\Http\Response
118
     */
119
    public function edit($id)
120
    {
121
        $attendance = $this->repository->find($id);
122
123
        return view('attendances.edit', compact('attendance'));
124
    }
125
126
127
    /**
128
     * Update the specified resource in storage.
129
     *
130
     * @param  AttendanceUpdateRequest $request
131
     * @param  string            $id
132
     *
133
     * @return Response
134
     */
135
    public function update(AttendanceUpdateRequest $request, $id)
136
    {
137
        try {
138
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
139
140
            $attendance = $this->repository->update( $request->all(),$id);
141
142
            $response = [
143
                'message' => 'Attendance updated.',
144
                'data'    => $attendance->toArray(),
145
            ];
146
147
            if ($request->wantsJson()) {
148
                return response()->json($response);
149
            }
150
151
            return redirect()->back()->with('message', $response['message']);
152
        } catch (ValidatorException $e) {
153
            if ($request->wantsJson()) {
154
                return response()->json([
155
                    'error'   => true,
156
                    'message' => $e->getMessageBag()
157
                ]);
158
            }
159
160
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
161
        }
162
    }
163
164
165
    /**
166
     * Remove the specified resource from storage.
167
     *
168
     * @param  int $id
169
     *
170
     * @return \Illuminate\Http\Response
171
     */
172
    public function destroy($id)
173
    {
174
        $deleted = $this->repository->delete($id);
175
176
        if (request()->wantsJson()) {
177
            return response()->json([
178
                'message' => 'Attendance deleted.',
179
                'deleted' => $deleted,
180
            ]);
181
        }
182
183
        return redirect()->back()->with('message', 'Attendance deleted.');
184
    }
185
}
186

src/Http/Controllers/DesirataController.php 1 location

@@ 15-197 (lines=183) @@
12
use Scool\Timetables\Validators\DesiratumValidator;
13
14
15
class DesirataController extends Controller
16
{
17
18
    /**
19
     * @var DesiratumRepository
20
     */
21
    protected $repository;
22
23
    /**
24
     * @var DesiratumValidator
25
     */
26
    protected $validator;
27
28
    public function __construct(DesiratumRepository $repository, DesiratumValidator $validator)
29
    {
30
        $this->repository = $repository;
31
        $this->validator  = $validator;
32
    }
33
34
35
    /**
36
     * Display a listing of the resource.
37
     *
38
     * @return \Illuminate\Http\Response
39
     */
40
    public function index()
41
    {
42
        $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
43
        $desirata = $this->repository->all();
44
45
        if (request()->wantsJson()) {
46
47
            return response()->json([
48
                'data' => $desirata,
49
            ]);
50
        }
51
52
        return view('desirata.index', compact('desirata'));
53
    }
54
55
    /**
56
     * Store a newly created resource in storage.
57
     *
58
     * @param  DesiratumCreateRequest $request
59
     *
60
     * @return \Illuminate\Http\Response
61
     */
62
    public function store(DesiratumCreateRequest $request)
63
    {
64
65
        try {
66
67
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
68
69
            $desiratum = $this->repository->create($request->all());
70
71
            $response = [
72
                'message' => 'Desiratum created.',
73
                'data'    => $desiratum->toArray(),
74
            ];
75
76
            if ($request->wantsJson()) {
77
78
                return response()->json($response);
79
            }
80
81
            return redirect()->back()->with('message', $response['message']);
82
        } catch (ValidatorException $e) {
83
            if ($request->wantsJson()) {
84
                return response()->json([
85
                    'error'   => true,
86
                    'message' => $e->getMessageBag()
87
                ]);
88
            }
89
90
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
91
        }
92
    }
93
94
95
    /**
96
     * Display the specified resource.
97
     *
98
     * @param  int $id
99
     *
100
     * @return \Illuminate\Http\Response
101
     */
102
    public function show($id)
103
    {
104
        $desiratum = $this->repository->find($id);
105
106
        if (request()->wantsJson()) {
107
108
            return response()->json([
109
                'data' => $desiratum,
110
            ]);
111
        }
112
113
        return view('desirata.show', compact('desiratum'));
114
    }
115
116
117
    /**
118
     * Show the form for editing the specified resource.
119
     *
120
     * @param  int $id
121
     *
122
     * @return \Illuminate\Http\Response
123
     */
124
    public function edit($id)
125
    {
126
127
        $desiratum = $this->repository->find($id);
128
129
        return view('desirata.edit', compact('desiratum'));
130
    }
131
132
133
    /**
134
     * Update the specified resource in storage.
135
     *
136
     * @param  DesiratumUpdateRequest $request
137
     * @param  string            $id
138
     *
139
     * @return Response
140
     */
141
    public function update(DesiratumUpdateRequest $request, $id)
142
    {
143
144
        try {
145
146
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
147
148
            $desiratum = $this->repository->update($request->all(), $id);
149
150
            $response = [
151
                'message' => 'Desiratum updated.',
152
                'data'    => $desiratum->toArray(),
153
            ];
154
155
            if ($request->wantsJson()) {
156
157
                return response()->json($response);
158
            }
159
160
            return redirect()->back()->with('message', $response['message']);
161
        } catch (ValidatorException $e) {
162
163
            if ($request->wantsJson()) {
164
165
                return response()->json([
166
                    'error'   => true,
167
                    'message' => $e->getMessageBag()
168
                ]);
169
            }
170
171
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
172
        }
173
    }
174
175
176
    /**
177
     * Remove the specified resource from storage.
178
     *
179
     * @param  int $id
180
     *
181
     * @return \Illuminate\Http\Response
182
     */
183
    public function destroy($id)
184
    {
185
        $deleted = $this->repository->delete($id);
186
187
        if (request()->wantsJson()) {
188
189
            return response()->json([
190
                'message' => 'Desiratum deleted.',
191
                'deleted' => $deleted,
192
            ]);
193
        }
194
195
        return redirect()->back()->with('message', 'Desiratum deleted.');
196
    }
197
}
198