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 +
+ + @php($old_topico = old('topico_id')) + + @error('topico_id') +
{{ $message }}
+ @enderror +
diff --git a/resources/views/topico/index.blade.php b/resources/views/topico/index.blade.php index 65f2bdb..05ef9f5 100644 --- a/resources/views/topico/index.blade.php +++ b/resources/views/topico/index.blade.php @@ -15,9 +15,9 @@ href="{{ URL::to('exercicio/create') }}">Cadastrar exercicio @endcan - @can ('order', App\Models\Topico::class) + @can ('sort', App\Models\Topico::class) Reordenar topicos + href="{{ URL::to('topico/sort') }}">Reordenar topicos @endcan @can ('create', App\Models\Topico::class) diff --git a/resources/views/topico/sort.blade.php b/resources/views/topico/sort.blade.php new file mode 100644 index 0000000..4a316e1 --- /dev/null +++ b/resources/views/topico/sort.blade.php @@ -0,0 +1,35 @@ +@extends('layouts.base') +@section('content') + +
+
+ @csrf + @method ('put') + +
+ Arraste para reordenar! +
+ + + + + + + + @foreach (old('topico_id', $topicos) as $value) + + + + @endforeach + +
Tópico
+ + {{ $value->name }} +
+ +
+
+@endsection diff --git a/routes/web.php b/routes/web.php index ab04969..6575fb5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,6 +43,9 @@ Route::get('/exercicio/{exercicio}/export', [ExercicioController::class, 'export'])->name('exercicio.export'); Route::put('/exercicio/{exercicio}/import', [ExercicioController::class, 'importEdit']); +Route::get('/topico/sort', [TopicoController::class, 'sort'])->name('topico.sort'); +Route::put('/topico/sort', [TopicoController::class, 'order'])->name('topico.order'); + Route::resources([ 'user' => UserController::class, 'turma' => TurmaController::class,