diff --git a/app/Http/Controllers/ExercicioController.php b/app/Http/Controllers/ExercicioController.php index bb794fa..ac21ce8 100644 --- a/app/Http/Controllers/ExercicioController.php +++ b/app/Http/Controllers/ExercicioController.php @@ -48,7 +48,9 @@ public function index() public function create() { $this->authorize('create', Exercicio::class); - return View('exercicio.create')->with('pacotesR', $this->getInstalledPackages()); + return View('exercicio.create') + ->with('pacotesR', $this->getInstalledPackages()) + ->with('topicos', Topico::orderBy('order')); } /** diff --git a/app/Http/Controllers/TopicoController.php b/app/Http/Controllers/TopicoController.php index 81127aa..7dd7ade 100644 --- a/app/Http/Controllers/TopicoController.php +++ b/app/Http/Controllers/TopicoController.php @@ -100,6 +100,37 @@ public function destroy(Topico $topico) $topico->exercicios()->detach(); $topico->delete(); + return redirect()->action([get_class($this), 'index']); + } + + /** + * Show form for reordering of Topico + */ + public function sort() + { + $this->authorize('sort', Topico::class); + $topicos = Topico::orderBy('order')->get(); + + return View('topico.sort')->with('topicos', $topicos); + } + + /** + * Update order of topicos + */ + public function order(Request $request) + { + $this->authorize('sort', Topico::class); + $rules = [ + 'topico_id.*' => 'required|int', + ]; + + $data = $request->validate($rules); + foreach($data['topico_id'] as $i => $id) { + + } + + + return redirect()->action([get_class($this), 'index']); } } diff --git a/app/Policies/TopicoPolicy.php b/app/Policies/TopicoPolicy.php index ecac8b0..1c2ce08 100644 --- a/app/Policies/TopicoPolicy.php +++ b/app/Policies/TopicoPolicy.php @@ -74,7 +74,7 @@ public function delete(User $user, Topico $topico) * @param \App\Models\User $user * @return mixed */ - public function order(User $user) + public function sort(User $user) { return $user->isAdmin(); } diff --git a/resources/views/exercicio/create.blade.php b/resources/views/exercicio/create.blade.php index fd7ab88..0d18804 100644 --- a/resources/views/exercicio/create.blade.php +++ b/resources/views/exercicio/create.blade.php @@ -34,6 +34,19 @@ @enderror +