diff --git a/app/Http/Controllers/DependenciaController.php b/app/Http/Controllers/DependenciaController.php new file mode 100644 index 0000000000000000000000000000000000000000..d39ac022a68c1239961f21bea5ead71a2a61efdd --- /dev/null +++ b/app/Http/Controllers/DependenciaController.php @@ -0,0 +1,86 @@ + $dependencias]); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + $validated = $request->validate([ + 'nombre' => 'required|max:150', + ]); + + $dependencia = new Dependencia; + $dependencia->nombre = $request->nombre; + $dependencia->save(); + return redirect()->route('catalogos.dependencias.get')->with('success', 'Dependencia creada correctamente.'); + } + + /** + * Display the specified resource. + */ + public function show(Dependencia $dependencia) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(Dependencia $dependencia) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, Dependencia $dependencia) + { + $validated = $request->validate([ + 'id' => 'required:min:1', + 'nombre' => 'required|max:150', + ]); + $dependencia = Dependencia::find($request->id); + $dependencia->nombre = $request->nombre; + $dependencia->save(); + return redirect()->route('catalogos.dependencias.get')->with('success', 'Dependencia actualizada correctamente.'); + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + try{ + $dependencia = Dependencia::findOrFail($id); + $dependencia->delete(); + return redirect()->route('catalogos.dependencias.get')->with('success', 'Dependencia eliminada correctamente.'); + }catch(\Exception $e){ + return redirect()->route('catalogos.dependencias.get')->withErrors('Error al eliminar la dependencia:' . $e->getMessage()); + } + } +} diff --git a/app/Models/Dependencia.php b/app/Models/Dependencia.php new file mode 100644 index 0000000000000000000000000000000000000000..a7d772bac673d68126c814b19ac5dbb3ee509d53 --- /dev/null +++ b/app/Models/Dependencia.php @@ -0,0 +1,24 @@ +hasMany(User::class); + } +} diff --git a/database/migrations/2024_06_10_154242_create_dependencias_table.php b/database/migrations/2024_06_10_154242_create_dependencias_table.php new file mode 100644 index 0000000000000000000000000000000000000000..718a95cef41bedab8c52c3ea51654ff4ffb3e61b --- /dev/null +++ b/database/migrations/2024_06_10_154242_create_dependencias_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('nombre'); + $table->timestamps(); + }); + + Schema::table('users', function(Blueprint $table){ + $table->unsignedBigInteger('dependencia_id'); + + $table->foreign('dependencia_id')->references('id')->on('dependencias'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('dependencias'); + } +}; diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 74e53e901f2513f64a2b17c0f1864bd1b783d5e1..48dba52ac0633a1e3d9c667fe2e6981e9483e26c 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -5,6 +5,7 @@ use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; use App\Models\User; +use App\Models\Dependencia; use Illuminate\Support\Facades\Hash; use Spatie\Permission\Models\Role; @@ -21,12 +22,14 @@ public function run(): void $roleAdmin = Role::create(['name' => 'admin']); $roleCap = Role::create(['name' => 'capturista']); $roleLector = Role::create(['name' => 'lector']); + $dependencia = Dependencia::create(['nombre' => 'Administración']); $user = User::create([ 'name' => 'Administración general', 'username' => 'admingen', 'active' => 1, 'password' => Hash::make('12345678'), + 'dependencia_id' => 1, ]); $user->assignRole('admingen'); @@ -35,6 +38,7 @@ public function run(): void 'username' => 'admin', 'active' => 1, 'password' => Hash::make('12345678'), + 'dependencia_id' => 1, ]); $user->assignRole('admin'); @@ -43,6 +47,7 @@ public function run(): void 'username' => 'capturista', 'active' => 1, 'password' => Hash::make('12345678'), + 'dependencia_id' => 1, ]); $user->assignRole('capturista'); @@ -51,6 +56,7 @@ public function run(): void 'username' => 'lector', 'active' => 1, 'password' => Hash::make('12345678'), + 'dependencia_id' => 1, ]); $user->assignRole('lector'); diff --git a/resources/views/adminGen/catalogos/dependencias.blade.php b/resources/views/adminGen/catalogos/dependencias.blade.php index 6f36f7b161e50a72fa2cbcd0fa79cf82980c0ef0..1246fae57403f4aad7ddcbbace934604ac677cb5 100644 --- a/resources/views/adminGen/catalogos/dependencias.blade.php +++ b/resources/views/adminGen/catalogos/dependencias.blade.php @@ -1,17 +1,275 @@ - -
+ + + +
  • Dashboard
  • - Analytics + Catálogos +
  • +
  • + Dependencias
-
- +
+ +
+
+
+ + + +
+
+
+ + + + + + + + + +
IdNombreAcciones
+
- + + + + + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index ad319f195a029bc9b037f613a2806010b20e95a0..dd0beda53b553c1eeaf3a7c4238d26a6a6b7c0a8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,7 +1,10 @@ name('dashboard'); }); + + +Route::name('catalogos.')->group(function () { + Route::get('/catalogos/dependencias', [DependenciaController::class, 'index'])->name('dependencias.get'); + 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'); +}); +