From a075408d759ab07c25fa6eb8ffa2f1817bbc3bab Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Mon, 17 Jun 2024 19:29:54 -0600 Subject: [PATCH 01/11] Eliminar archivos mal configurados --- app/Http/Controllers/subgrupoController.php | 10 ------ app/Models/subgrupo.php | 11 ------- ...24_06_03_194040_create_subgrupos_table.php | 32 ------------------- 3 files changed, 53 deletions(-) delete mode 100644 app/Http/Controllers/subgrupoController.php delete mode 100644 app/Models/subgrupo.php delete mode 100644 database/migrations/2024_06_03_194040_create_subgrupos_table.php diff --git a/app/Http/Controllers/subgrupoController.php b/app/Http/Controllers/subgrupoController.php deleted file mode 100644 index 12badd4..0000000 --- a/app/Http/Controllers/subgrupoController.php +++ /dev/null @@ -1,10 +0,0 @@ -id(); - $table->unsignedBigInteger('grupo_id')->nullable(); - $table->unsignedBigInteger('subgrupo_id')->nullable(); - $table->timestamps(); - - $table->foreign('grupo_id')->references('id')->on('grupos')->nullable(); - $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->nullable(); - }); - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::dropIfExists('subgrupos'); - } -}; -- GitLab From ff3a342e580c85ad5751259180d5d7934dadee96 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Mon, 17 Jun 2024 19:34:05 -0600 Subject: [PATCH 02/11] Modelo de subgrupos --- app/Models/Subgrupo.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/Models/Subgrupo.php diff --git a/app/Models/Subgrupo.php b/app/Models/Subgrupo.php new file mode 100644 index 0000000..0dce2f8 --- /dev/null +++ b/app/Models/Subgrupo.php @@ -0,0 +1,17 @@ + Date: Mon, 17 Jun 2024 19:34:13 -0600 Subject: [PATCH 03/11] Migracion de subgrupos --- ...24_06_18_013012_create_subgrupos_table.php | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 database/migrations/2024_06_18_013012_create_subgrupos_table.php diff --git a/database/migrations/2024_06_18_013012_create_subgrupos_table.php b/database/migrations/2024_06_18_013012_create_subgrupos_table.php new file mode 100644 index 0000000..73a8f5e --- /dev/null +++ b/database/migrations/2024_06_18_013012_create_subgrupos_table.php @@ -0,0 +1,33 @@ +id(); + $table->string('nombre'); + $table->unsignedBigInteger('grupo_id')->nullable(); + $table->unsignedBigInteger('subgrupo_id')->nullable(); + + $table->foreign('grupo_id')->references('id')->on('grupos')->nullable(); + $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('subgrupos'); + } +}; -- GitLab From 6bc89e28c4a44717879cf405b16214f4834ce358 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Mon, 17 Jun 2024 19:34:35 -0600 Subject: [PATCH 04/11] Ruta de vista principal de subgrupos --- routes/web.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routes/web.php b/routes/web.php index 95e14f6..300baa5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -8,6 +8,7 @@ use App\Http\Controllers\CaracteristicasController; use App\Http\Controllers\DependenciaController; use App\Http\Controllers\GruposController; +use App\Http\Controllers\SubgrupoController; use App\Http\Controllers\UserController; Route::get('/', function () { @@ -47,6 +48,8 @@ Route::post('/catalogos/dependencias', [DependenciaController::class, 'store'])->name('dependencias.store'); Route::put('/catalogos/dependencias', [DependenciaController::class, 'update'])->name('dependencias.update'); Route::delete('/catalogos/dependencias/{id}', [DependenciaController::class, 'destroy'])->name('dependencias.destroy'); + + Route::get('/catalogos/grupos/subgrupos', [SubgrupoController::class, 'index'])->name('subgrupos.get'); }); Route::name('usuarios.')->group(function () { -- GitLab From 6a1f3ff5d55f8a1195728d5c43bb36a2df5746b8 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Mon, 17 Jun 2024 23:35:59 -0600 Subject: [PATCH 05/11] Controlador de subgrupos --- app/Http/Controllers/SubgrupoController.php | 68 +++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/Http/Controllers/SubgrupoController.php diff --git a/app/Http/Controllers/SubgrupoController.php b/app/Http/Controllers/SubgrupoController.php new file mode 100644 index 0000000..4cdb607 --- /dev/null +++ b/app/Http/Controllers/SubgrupoController.php @@ -0,0 +1,68 @@ + Date: Mon, 17 Jun 2024 23:36:11 -0600 Subject: [PATCH 06/11] vista pricipal de subgrupos --- .../catalogos/subgrupos/index.blade.php | 128 ++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 resources/views/adminGen/catalogos/subgrupos/index.blade.php diff --git a/resources/views/adminGen/catalogos/subgrupos/index.blade.php b/resources/views/adminGen/catalogos/subgrupos/index.blade.php new file mode 100644 index 0000000..0164c6f --- /dev/null +++ b/resources/views/adminGen/catalogos/subgrupos/index.blade.php @@ -0,0 +1,128 @@ + + + + + +
+ + +
+ + + + + + + + + +
\ No newline at end of file -- GitLab From 7bc161637403ac5723786c4086adb1019faadeec Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Wed, 19 Jun 2024 10:03:21 -0600 Subject: [PATCH 07/11] Subgrupos --- app/Http/Controllers/SubgrupoController.php | 7 +- .../catalogos/subgrupos/create.blade.php | 167 ++++++++++++++++++ .../catalogos/subgrupos/index.blade.php | 2 +- routes/web.php | 1 + 4 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 resources/views/adminGen/catalogos/subgrupos/create.blade.php diff --git a/app/Http/Controllers/SubgrupoController.php b/app/Http/Controllers/SubgrupoController.php index 4cdb607..d19e301 100644 --- a/app/Http/Controllers/SubgrupoController.php +++ b/app/Http/Controllers/SubgrupoController.php @@ -14,8 +14,7 @@ class SubgrupoController extends Controller public function index() { $subgrupos = Subgrupo::get(); - $grupos = Grupos::get(); - return view('adminGen.catalogos.subgrupos.index', compact('subgrupos', 'grupos')); + return view('adminGen.catalogos.subgrupos.index', compact('subgrupos')); } /** @@ -23,7 +22,9 @@ public function index() */ public function create() { - // + $subgrupos = Subgrupo::get(); + $grupos = Grupos::get(); + return view('adminGen.catalogos.subgrupos.create', compact('subgrupos', 'grupos')); } /** diff --git a/resources/views/adminGen/catalogos/subgrupos/create.blade.php b/resources/views/adminGen/catalogos/subgrupos/create.blade.php new file mode 100644 index 0000000..5847c27 --- /dev/null +++ b/resources/views/adminGen/catalogos/subgrupos/create.blade.php @@ -0,0 +1,167 @@ + + + + +
+ +
+
+
Crear nuevo subgrupo
+
+
+
+ @csrf +
+
+ + +
+
+ + +
+
+ + +
+ Nota: Solo es posible seleccionar un grupo o un subgrupo, más no ambos. +
+ +
+
+
+
+ + + + + + + + + + + +
\ No newline at end of file diff --git a/resources/views/adminGen/catalogos/subgrupos/index.blade.php b/resources/views/adminGen/catalogos/subgrupos/index.blade.php index 0164c6f..45d36c9 100644 --- a/resources/views/adminGen/catalogos/subgrupos/index.blade.php +++ b/resources/views/adminGen/catalogos/subgrupos/index.blade.php @@ -20,7 +20,7 @@
- + diff --git a/routes/web.php b/routes/web.php index 300baa5..6c0a573 100644 --- a/routes/web.php +++ b/routes/web.php @@ -50,6 +50,7 @@ Route::delete('/catalogos/dependencias/{id}', [DependenciaController::class, 'destroy'])->name('dependencias.destroy'); Route::get('/catalogos/grupos/subgrupos', [SubgrupoController::class, 'index'])->name('subgrupos.get'); + Route::get('/catalogos/grupos/subgrupos/crear', [SubgrupoController::class, 'create'])->name('subgrupos.create'); }); Route::name('usuarios.')->group(function () { -- GitLab From 072fae5db8ebffc128ec2d074eec70c0d1b934f1 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Fri, 21 Jun 2024 13:14:26 -0600 Subject: [PATCH 08/11] Controlador de subgrupos --- app/Http/Controllers/SubgrupoController.php | 45 +++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/SubgrupoController.php b/app/Http/Controllers/SubgrupoController.php index d19e301..a3adcd6 100644 --- a/app/Http/Controllers/SubgrupoController.php +++ b/app/Http/Controllers/SubgrupoController.php @@ -13,7 +13,8 @@ class SubgrupoController extends Controller */ public function index() { - $subgrupos = Subgrupo::get(); + $subgrupos = Subgrupo::with('grupo')->with('subgrupo')->get(); + return view('adminGen.catalogos.subgrupos.index', compact('subgrupos')); } @@ -32,7 +33,13 @@ public function create() */ public function store(Request $request) { - // + $subgrupo = new Subgrupo; + $subgrupo->nombre = $request->nombre; + if(isset($request->grupo_id) && isset($request->subgrupo_id)) return redirect()->route('catalogos.subgrupos.create')->withErrors('Error al crear el subgrupo, solo es posible seleccionar un grupo o un subgrupo.'); + if(isset($request->grupo_id)) $subgrupo->grupo_id = $request->grupo_id; + if(isset($request->subgrupo_id)) $subgrupo->subgrupo_id = $request->subgrupo_id; + $subgrupo->save(); + return redirect()->route('catalogos.subgrupos.get')->with('success', 'Subgrupo creado correctamente.'); } /** @@ -46,24 +53,46 @@ public function show(Subgrupo $subgrupo) /** * Show the form for editing the specified resource. */ - public function edit(Subgrupo $subgrupo) + public function edit(string $id) { - // + $subgrupos = Subgrupo::where('id', '!=', $id)->get(); + $subgrupo = Subgrupo::findOrFail($id); + $grupos = Grupos::get(); + + return view('adminGen.catalogos.subgrupos.edit', compact('subgrupos', 'grupos', 'subgrupo')); } /** * Update the specified resource in storage. */ - public function update(Request $request, Subgrupo $subgrupo) + public function update(Request $request, string $id) { - // + $subgrupo = Subgrupo::findOrFail($id); + $subgrupo->nombre = $request->nombre; + if(isset($request->grupo_id) && isset($request->subgrupo_id)) return redirect()->route('catalogos.subgrupos.create')->withErrors('Error al crear el subgrupo, solo es posible seleccionar un grupo o un subgrupo.'); + if(isset($request->grupo_id)){ + $subgrupo->grupo_id = $request->grupo_id; + $subgrupo->subgrupo_id = null; + } + if(isset($request->subgrupo_id)){ + $subgrupo->subgrupo_id = $request->subgrupo_id; + $subgrupo->grupo_id = null; + } + $subgrupo->save(); + return redirect()->route('catalogos.subgrupos.get')->with('success', 'Subgrupo actualizado correctamente.'); } /** * Remove the specified resource from storage. */ - public function destroy(Subgrupo $subgrupo) + public function destroy(string $id) { - // + try{ + $subgrupo = Subgrupo::findOrFail($id); + $subgrupo->delete(); + return redirect()->route('catalogos.subgrupos.get')->with('success', 'Subgrupo eliminado correctamente.'); + }catch(\Exception $e){ + return redirect()->route('catalogos.subgrupos.get')->withErrors('Error al eliminar el subgrupo:' . $e->getMessage()); + } } } -- GitLab From b46c6c15ab94344b67022267f765a5e6a9eafde4 Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Fri, 21 Jun 2024 13:14:37 -0600 Subject: [PATCH 09/11] Modelo de subgrupos --- app/Models/Subgrupo.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Models/Subgrupo.php b/app/Models/Subgrupo.php index 0dce2f8..084a8fc 100644 --- a/app/Models/Subgrupo.php +++ b/app/Models/Subgrupo.php @@ -4,6 +4,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasOne; class Subgrupo extends Model { @@ -14,4 +16,14 @@ class Subgrupo extends Model 'grupo_id', 'subgrupo_id', ]; + + public function grupo(): BelongsTo + { + return $this->belongsTo(Grupos::class); + } + + public function subgrupo(): BelongsTo + { + return $this->belongsTo(Subgrupo::class); + } } -- GitLab From cec2371a7affb0668295875133f4e1cb6240d6ec Mon Sep 17 00:00:00 2001 From: Alfonso Rafael Solis Rangel Date: Fri, 21 Jun 2024 13:15:08 -0600 Subject: [PATCH 10/11] Vistar de crud de los subgrupos --- .../catalogos/subgrupos/create.blade.php | 27 +-- .../catalogos/subgrupos/edit.blade.php | 168 ++++++++++++++++++ .../catalogos/subgrupos/index.blade.php | 16 +- 3 files changed, 186 insertions(+), 25 deletions(-) create mode 100644 resources/views/adminGen/catalogos/subgrupos/edit.blade.php diff --git a/resources/views/adminGen/catalogos/subgrupos/create.blade.php b/resources/views/adminGen/catalogos/subgrupos/create.blade.php index 5847c27..e158004 100644 --- a/resources/views/adminGen/catalogos/subgrupos/create.blade.php +++ b/resources/views/adminGen/catalogos/subgrupos/create.blade.php @@ -10,7 +10,7 @@
  • Catálogos
  • -
  • +
  • Grupos
  • @@ -25,7 +25,7 @@
    Crear nuevo subgrupo
  • -
    + @csrf
    @@ -46,7 +46,7 @@
    @@ -67,6 +67,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/views/adminGen/catalogos/subgrupos/index.blade.php b/resources/views/adminGen/catalogos/subgrupos/index.blade.php index 45d36c9..40895bd 100644 --- a/resources/views/adminGen/catalogos/subgrupos/index.blade.php +++ b/resources/views/adminGen/catalogos/subgrupos/index.blade.php @@ -11,7 +11,7 @@
  • Catálogos
  • -
  • +
  • Grupos
  • @@ -49,28 +49,20 @@