diff --git a/app/Http/Controllers/ContactoController.php b/app/Http/Controllers/ContactoController.php
index 5cf2f249665b76ad6e5ac96a080c24e1fd993f56..89b88168ecee75ab7a114731bcf9f0ee38525dbd 100644
--- a/app/Http/Controllers/ContactoController.php
+++ b/app/Http/Controllers/ContactoController.php
@@ -7,6 +7,7 @@
use App\Models\cargos;
use App\Models\Contacto;
use App\Models\CorreoContactos;
+use App\Models\Grupos;
use App\Models\Profesion;
use App\Models\Subgrupo;
use App\Models\Telefono;
@@ -40,7 +41,8 @@ public function create()
$cargos = cargos::get();
$caracteristicas = Caracteristicas::get();
$subgrupos = Subgrupo::get();
- return view('adminGen.contactos.create', compact('conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos'));
+ $grupos = Grupos::get();
+ return view('adminGen.contactos.create', compact('conyuges', 'profesiones', 'cargos', 'caracteristicas', 'subgrupos', 'grupos'));
}
/**
@@ -51,6 +53,7 @@ public function store(Request $request)
$request->validate([
'foto_perfil' => 'image|mimes:jpeg,png,jpg,gif|max:2048',
'nombre' => 'required|max:255|string',
+ 'ap_paterno' => 'required|max:255|string',
]);
$telefonosData = $request->only(['prefijo', 'lada', 'numero', 'tipo', 'estatus', 'ext', 'id_radio', 'observaciones']);
@@ -84,7 +87,6 @@ public function store(Request $request)
'profesion_id',
'cargo_id',
'caracteristica_id',
- 'subgrupo_id',
'mes_cump',
'dia_cump',
//institucion_id
@@ -95,7 +97,6 @@ public function store(Request $request)
unset($requestData[$field]);
}
}
-
$request->replace($requestData);
$data = $request->all();
@@ -132,6 +133,15 @@ public function store(Request $request)
throw new \Exception('Error al guardar los correos electrónicos');
}
+ // Sincronizar subgrupos y grupos
+ if ($request->has('subgrupo_id')) {
+ $contacto->subgrupos()->sync($request->input('subgrupo_id'));
+ }
+
+ if ($request->has('grupo_id')) {
+ $contacto->grupos()->sync($request->input('grupo_id'));
+ }
+
DB::commit();
return redirect()->route('contacto.get')->with('success', 'Contacto guardado correctamente');
}catch (\Exception $e){
diff --git a/app/Http/Controllers/ListaController.php b/app/Http/Controllers/ListaController.php
new file mode 100644
index 0000000000000000000000000000000000000000..7de7e42b7407e4b1c936577ecba44492c76157cb
--- /dev/null
+++ b/app/Http/Controllers/ListaController.php
@@ -0,0 +1,119 @@
+validate([
+ 'nombre' => 'required|string|max:255',
+ ]);
+
+ $lista = Lista::create($request->only('nombre'));
+
+ $grupoIds = array_filter($request->input('grupo_id', []), fn($value) => $value !== 'null');
+ $subgrupoIds = array_filter($request->input('subgrupo_id', []), fn($value) => $value !== 'null');
+ $contactoIds = array_filter($request->input('contacto_id', []), fn($value) => $value !== 'null');
+
+ // Sincronizar relaciones
+ $lista->grupos()->sync($grupoIds);
+ $lista->subgrupos()->sync($subgrupoIds);
+ $lista->contactos()->sync($contactoIds);
+
+ return redirect()->route('listas.get')->with('success', 'Lista creada correctamente.');
+ }
+
+ /**
+ * Display the specified resource.
+ */
+ public function show(string $id)
+ {
+ $lista = Lista::with('contactos', 'grupos', 'subgrupos')->findOrFail($id);
+ return view('adminGen.listas.show', compact('lista'));
+ }
+
+ /**
+ * Show the form for editing the specified resource.
+ */
+ public function edit(string $id)
+ {
+ $contactos = Contacto::get();
+ $grupos = Grupos::get();
+ $subgrupos = Subgrupo::get();
+ $lista = Lista::with('contactos', 'grupos', 'subgrupos')->findOrFail($id);
+ return view('adminGen.listas.edit', compact('lista', 'contactos', 'grupos', 'subgrupos'));
+ }
+
+ /**
+ * Update the specified resource in storage.
+ */
+ public function update(Request $request, string $id)
+ {
+ // Validar solo los campos necesarios
+ $request->validate([
+ 'nombre' => 'required|string|max:255',
+ ]);
+
+ // Recuperar la lista existente
+ $lista = Lista::findOrFail($id);
+
+ // Actualizar el nombre
+ $lista->update($request->only('nombre'));
+
+ // Filtrar valores null y cadenas "null" antes de sincronizar
+ $grupoIds = array_filter($request->input('grupo_id', []), fn($value) => $value !== 'null');
+ $subgrupoIds = array_filter($request->input('subgrupo_id', []), fn($value) => $value !== 'null');
+ $contactoIds = array_filter($request->input('contacto_id', []), fn($value) => $value !== 'null');
+
+ // Sincronizar relaciones
+ $lista->grupos()->sync($grupoIds);
+ $lista->subgrupos()->sync($subgrupoIds);
+ $lista->contactos()->sync($contactoIds);
+
+ return redirect()->route('listas.get')->with('success', 'Lista actualizada correctamente.');
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ */
+ public function destroy(string $id)
+ {
+ try{
+ $lista = Lista::findOrFail($id);
+ $lista->delete();
+ return redirect()->route('listas.get')->with('success', 'Lista eliminada correctamente.');
+ }catch(\Exception $e){
+ return redirect()->route('contacto.get')->withErrors('Error al eliminar la lista.');
+ }
+ }
+}
diff --git a/app/Models/Contacto.php b/app/Models/Contacto.php
index 675b3e8ac000b342ef1c6f149bc72983bd147834..64d6ae5ab78cd23e304dc03e310000a8b287c959 100644
--- a/app/Models/Contacto.php
+++ b/app/Models/Contacto.php
@@ -5,6 +5,8 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\HasMany;
class Contacto extends Model
{
@@ -38,7 +40,6 @@ class Contacto extends Model
'cargo_id',
'caracteristica_id',
//'institucion_id',
- 'subgrupo_id',
];
public function profesion(): BelongsTo
@@ -56,18 +57,33 @@ public function cargo(): BelongsTo
return $this->belongsTo(cargos::class);
}
- public function telefonos()
+ public function telefonos(): HasMany
{
return $this->hasMany(Telefono::class);
}
- public function redes()
+ public function redes(): HasMany
{
return $this->hasMany(RedesSociales::class);
}
- public function correos()
+ public function correos(): HasMany
{
return $this->hasMany(CorreoContactos::class);
}
+
+ public function listas(): BelongsToMany
+ {
+ return $this->belongsToMany(Lista::class, 'listas_contactos', 'contacto_id', 'lista_id');
+ }
+
+ public function subgrupos(): BelongsToMany
+ {
+ return $this->belongsToMany(Subgrupo::class, 'contactos_subgrupos', 'contacto_id', 'subgrupo_id');
+ }
+
+ public function grupos(): BelongsToMany
+ {
+ return $this->belongsToMany(Grupos::class, 'contactos_grupos', 'contacto_id', 'grupo_id');
+ }
}
diff --git a/app/Models/Grupos.php b/app/Models/Grupos.php
index 57cea9a6c64ed2776f8fcf7e5b8d7de5127a1c8e..426746206471317a40a1811559ad1a88aaad9af5 100644
--- a/app/Models/Grupos.php
+++ b/app/Models/Grupos.php
@@ -4,6 +4,8 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\HasMany;
class Grupos extends Model
{
@@ -19,6 +21,16 @@ public function users(): HasMany {
return $this->hasMany(User::class);
}
+
+ public function listas(): BelongsToMany
+ {
+ return $this->belongsToMany(Lista::class, 'listas_grupos', 'grupo_id', 'lista_id');
+ }
+
+ public function contactos(): BelongsToMany
+ {
+ return $this->belongsToMany(Contacto::class, 'contactos_grupos', 'contacto_id', 'grupo_id');
+ }
public $timestamps = false;
}
diff --git a/app/Models/Lista.php b/app/Models/Lista.php
new file mode 100644
index 0000000000000000000000000000000000000000..485e14a57134a81bbf74898dcd777a3772a10e03
--- /dev/null
+++ b/app/Models/Lista.php
@@ -0,0 +1,30 @@
+belongsToMany(Contacto::class, 'listas_contactos', 'lista_id', 'contacto_id');
+ }
+
+ public function grupos(): BelongsToMany
+ {
+ return $this->belongsToMany(Grupos::class, 'listas_grupos', 'lista_id', 'grupo_id');
+ }
+
+ public function subgrupos(): BelongsToMany
+ {
+ return $this->belongsToMany(Subgrupo::class, 'listas_subgrupos', 'lista_id', 'subgrupo_id');
+ }
+}
diff --git a/app/Models/Subgrupo.php b/app/Models/Subgrupo.php
index fe4200ac713312ba98da6bd430c39f98e62a560e..0545c6ee742a9e7f73bdf84ef93bf2ad04d4c267 100644
--- a/app/Models/Subgrupo.php
+++ b/app/Models/Subgrupo.php
@@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Subgrupo extends Model
{
@@ -25,4 +26,14 @@ public function subgrupo(): BelongsTo
{
return $this->belongsTo(Subgrupo::class);
}
+
+ public function listas(): BelongsToMany
+ {
+ return $this->belongsToMany(Lista::class, 'listas_subgrupos', 'subgrupo_id', 'lista_id');
+ }
+
+ public function contactos(): BelongsToMany
+ {
+ return $this->belongsToMany(Contacto::class, 'contactos_subgrupos', 'contacto_id', 'subgrupo_id');
+ }
}
diff --git a/database/migrations/2024_06_23_201805_create_contactos_table.php b/database/migrations/2024_06_23_201805_create_contactos_table.php
index f85025dd7cbaf6f47c2c07636e58f0f80c8a3a12..8a808d87da39c923741cde6f6a094fe85a8f0713 100644
--- a/database/migrations/2024_06_23_201805_create_contactos_table.php
+++ b/database/migrations/2024_06_23_201805_create_contactos_table.php
@@ -39,14 +39,13 @@ public function up(): void
$table->unsignedBigInteger('cargo_id')->nullable();
$table->unsignedBigInteger('caracteristica_id')->nullable();
//$table->unsignedBigInteger('institucion_id')->nullable();
- $table->unsignedBigInteger('subgrupo_id')->nullable();
$table->foreign('conyuge_id')->references('id')->on('contactos')->nullable();
$table->foreign('profesion_id')->references('id')->on('profesions')->nullable();
//$table->foreign('institucion_id')->references('id')->on('')->nullable();
$table->foreign('cargo_id')->references('id')->on('cargos')->nullable();
$table->foreign('caracteristica_id')->references('id')->on('caracteristicas')->nullable();
- $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->nullable();
+
$table->timestamps();
});
}
diff --git a/database/migrations/2024_07_05_151703_create_listas_table.php b/database/migrations/2024_07_05_151703_create_listas_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..c96bc2bf6f04ccc9ec39c1de5644ded85c71acfb
--- /dev/null
+++ b/database/migrations/2024_07_05_151703_create_listas_table.php
@@ -0,0 +1,28 @@
+id();
+ $table->string('nombre');
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('listas');
+ }
+};
diff --git a/database/migrations/2024_07_06_191407_create_listas_contactos_table.php b/database/migrations/2024_07_06_191407_create_listas_contactos_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..e2c5390dc87c57fb7df4c7879c1377b0fe349c87
--- /dev/null
+++ b/database/migrations/2024_07_06_191407_create_listas_contactos_table.php
@@ -0,0 +1,32 @@
+id();
+ $table->unsignedBigInteger('lista_id');
+ $table->unsignedBigInteger('contacto_id');
+ $table->timestamps();
+
+ $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade');
+ $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('listas_contactos');
+ }
+};
diff --git a/database/migrations/2024_07_06_192720_create_listas_grupos_table.php b/database/migrations/2024_07_06_192720_create_listas_grupos_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..d9346c7853854de13f0e6f0f0e1ccada570aff61
--- /dev/null
+++ b/database/migrations/2024_07_06_192720_create_listas_grupos_table.php
@@ -0,0 +1,32 @@
+id();
+ $table->unsignedBigInteger('grupo_id');
+ $table->unsignedBigInteger('lista_id');
+ $table->timestamps();
+
+ $table->foreign('grupo_id')->references('id')->on('grupos')->onDelete('cascade')->onUpdate('cascade');
+ $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('listas_grupos');
+ }
+};
diff --git a/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php b/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..6b351a62288d9a1c5899fefc07449978132cccc1
--- /dev/null
+++ b/database/migrations/2024_07_06_193217_create_listas_subgrupos_table.php
@@ -0,0 +1,32 @@
+id();
+ $table->unsignedBigInteger('subgrupo_id');
+ $table->unsignedBigInteger('lista_id');
+ $table->timestamps();
+
+ $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->onDelete('cascade')->onUpdate('cascade');
+ $table->foreign('lista_id')->references('id')->on('listas')->onDelete('cascade')->onUpdate('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('listas_subgrupos');
+ }
+};
diff --git a/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php b/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..c38554ad43100c4f99f18cbad10d14329b0cefbe
--- /dev/null
+++ b/database/migrations/2024_07_06_212341_create_contactos_subgrupos_table.php
@@ -0,0 +1,32 @@
+id();
+ $table->unsignedBigInteger('subgrupo_id');
+ $table->unsignedBigInteger('contacto_id');
+ $table->timestamps();
+
+ $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade');
+ $table->foreign('subgrupo_id')->references('id')->on('subgrupos')->onDelete('cascade')->onUpdate('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('contactos_subgrupos');
+ }
+};
diff --git a/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php b/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php
new file mode 100644
index 0000000000000000000000000000000000000000..519440a465b689ad3d983612c9c5b65ef5b0c375
--- /dev/null
+++ b/database/migrations/2024_07_06_213719_create_contactos_grupos_table.php
@@ -0,0 +1,32 @@
+id();
+ $table->unsignedBigInteger('grupo_id');
+ $table->unsignedBigInteger('contacto_id');
+ $table->timestamps();
+
+ $table->foreign('contacto_id')->references('id')->on('contactos')->onDelete('cascade')->onUpdate('cascade');
+ $table->foreign('grupo_id')->references('id')->on('grupos')->onDelete('cascade')->onUpdate('cascade');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('contactos_grupos');
+ }
+};
diff --git a/database/seeders/ContactoSeeder.php b/database/seeders/ContactoSeeder.php
new file mode 100644
index 0000000000000000000000000000000000000000..384224cbbda921a36c0bea857c075c7453627f57
--- /dev/null
+++ b/database/seeders/ContactoSeeder.php
@@ -0,0 +1,46 @@
+ $faker->firstName,
+ 'ap_paterno' => $faker->lastName,
+ 'ap_materno' => $faker->lastName,
+ 'cargo_desc' => $faker->jobTitle,
+ 'mes_cump' => $faker->month,
+ 'dia_cump' => $faker->dayOfMonth,
+ 'domicilio_oficial' => $faker->address,
+ 'codigo_postal' => $faker->postcode,
+ 'localidad_oficial' => $faker->city,
+ 'municipio_oficial' => $faker->city,
+ 'estado' => $faker->state,
+ 'pais' => $faker->country,
+ 'domicilio_par' => $faker->address,
+ 'codigo_postal_par' => $faker->postcode,
+ 'localidad_par' => $faker->city,
+ 'municipio_par' => $faker->city,
+ 'estado_par' => $faker->state,
+ 'pais_par' => $faker->country,
+ 'finado' => $faker->boolean,
+ 'foto_perfil' => $faker->imageUrl(),
+ ]);
+ }
+ }
+}
diff --git a/package-lock.json b/package-lock.json
index f8172d657090c74a07cfb87e72e6978084640105..97c2c5282f6807ab1f206d47bc7222686a8ec3f8 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,9 +1,12 @@
{
- "name": "html",
+ "name": "agendagobernador",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
+ "dependencies": {
+ "select2": "^4.1.0-rc.0"
+ },
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"@tailwindcss/typography": "^0.5.10",
@@ -2018,6 +2021,12 @@
"queue-microtask": "^1.2.2"
}
},
+ "node_modules/select2": {
+ "version": "4.1.0-rc.0",
+ "resolved": "https://registry.npmjs.org/select2/-/select2-4.1.0-rc.0.tgz",
+ "integrity": "sha512-Hr9TdhyHCZUtwznEH2CBf7967mEM0idtJ5nMtjvk3Up5tPukOLXbHUNmh10oRfeNIhj+3GD3niu+g6sVK+gK0A==",
+ "license": "MIT"
+ },
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
diff --git a/package.json b/package.json
index ff733f95dbb64a9a29558a59251e9a7bded96d85..26faa0510db43e0a735a58cc5c2503b40dfb6180 100644
--- a/package.json
+++ b/package.json
@@ -11,11 +11,14 @@
"autoprefixer": "^10.4.16",
"axios": "^1.6.4",
"laravel-vite-plugin": "^1.0",
+ "lodash": "^4.17.19",
"postcss": "^8.4.32",
- "tailwindcss": "^3.4.0",
- "vite": "^5.0",
"prettier": "^2.7.1",
"prettier-plugin-tailwindcss": "^0.1.13",
- "lodash": "^4.17.19"
+ "tailwindcss": "^3.4.0",
+ "vite": "^5.0"
+ },
+ "dependencies": {
+ "select2": "^4.1.0-rc.0"
}
}
diff --git a/resources/views/adminGen/contactos/create.blade.php b/resources/views/adminGen/contactos/create.blade.php
index c89c605a8096f8c3ce0d501660c584041ff6fa99..1fcd347d4a4ae719f7531309f9fd6aedfe1292f4 100644
--- a/resources/views/adminGen/contactos/create.blade.php
+++ b/resources/views/adminGen/contactos/create.blade.php
@@ -24,14 +24,15 @@
-
+
-
-
+
+
+ Grupos
+
+ -
+
- Domicilio oficial
+ Domicilio oficial
-
-
+
- Domicilio particular
+ Domicilio particular
-
-
+
- Teléfonos
+ Teléfonos
-
-
+
- Redes sociales
+ Redes sociales
-
-
+
- Correos electrónicos
+ Correos electrónicos
-
-
+
- Guardar contacto
+ Guardar contacto
@@ -131,7 +145,7 @@
@@ -235,8 +238,19 @@
-
+
+
@@ -265,8 +279,7 @@
-
-
+
@@ -295,7 +308,7 @@
-