Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
CRUD *- USUARIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Lara121801 committed Nov 24, 2022
1 parent 31aa89f commit f39cf03
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 64 deletions.
38 changes: 32 additions & 6 deletions app/Http/Controllers/UsuarioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Http\Controllers;

use App\Models\Usuario;
//use App\Models\Usuario;
use App\Models\User;
use App\Models\Persona;
use App\Models\TipoSangre;

use Illuminate\Http\Request;
class UsuarioController extends Controller
{
Expand All @@ -13,7 +17,9 @@ class UsuarioController extends Controller
*/
public function index()
{
//
$usuarios = user::with(['persona'])->get();
return view('admin.user.index', compact('usuarios'));
//return $usuario;
}
/**
* Show the form for creating a new resource.
Expand All @@ -22,7 +28,9 @@ public function index()
*/
public function create()
{
//
$personas = Persona::get();
$tipos_sangre = TipoSangre::get();
return view('admin.user.create', compact('tipos_sangre','personas'));
}

/**
Expand All @@ -33,7 +41,16 @@ public function create()
*/
public function store(Request $request)
{
//
$datos = $request->all();
Persona::create($datos);
$id = Persona::latest('id_persona')->first();
//return to_route('personas.index');
$datos1 = ['rol'=>"1", 'estado'=>1, 'id_persona'=>$id->id_persona];
$datosUser = array_merge($datos, $datos1);
User::create($datosUser);
return redirect('/Usuario');


}

/**
Expand Down Expand Up @@ -76,8 +93,17 @@ public function update(Request $request, Usuario $usuario)
* @param \App\Models\Usuario $usuario
* @return \Illuminate\Http\Response
*/
public function destroy(Usuario $usuario)
public function destroy(Request $request, $usuario)
{
//
$input = $request->all();

$usuarios = User::find($usuario);

$estado = ['estado'=>0];

$usuarios->update($estado);

//Redirecionas para no bugear el jalar de datos con reddirect para recargar la vista totalmente
return redirect('/Usuario');
}
}
3 changes: 3 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class User extends Authenticatable
'name',
'email',
'username',
'id_persona',
'rol',
'estado',
'password',
];

Expand Down
93 changes: 47 additions & 46 deletions resources/views/admin/Historial/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
<x-layouts.app>

<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-header">
<h2>Historias</h2>
</div>
<div class="card-body">
<a href="{{ url('/Historial/create') }}" class="btn btn-success btn-sm" title="Add New Student">
<i class="fa fa-plus" aria-hidden="true"></i> Nueva Historia
</a>
<br/>
<br/>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Persona</th>
<th>Sede</th>
<th>Medico</th>
<th>Fecha del Historial</th>
<th>Detalles de la Historia </th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
@foreach ($Historias as $Historia)
<tr>
<td>{{ $Historia->personas->nombre_per ." ".$Historia->personas->apellido_pa_per ." ".$Historia->personas->apellido_ma_per }}</td>
<td>{{ $Historia->sede->nombre_sede }}</td>
<td>{{ $Historia->users->persona->nombre_per ." ". $Historia->users->persona->apellido_pa_per ." ". $Historia->users->persona->apellido_ma_per}}</td>
<td>{{ $Historia->fecha_historial}}</td>
<td>{{ $Historia->detalles_historial }}</td>
<td>
<a href="{{ url('/Historial' . '/' . $Historia['id_historial']) }}" title="View Student"><button class="btn btn-info btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> Mostrar</button></a> <a href="{{ url('/Historial' . '/' . $Historia->id_historial . '/edit') }}" title="Edit Student"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Editar</button></a>
<form method="POST" action="{{ url('/Historial' . '/' . $Historia->id_historial) }}" accept-charset="UTF-8" style="display:inline">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm" title="Delete Student" onclick="return confirm(&quot;Confirm delete?&quot;)"><i class="fa fa-trash-o" aria-hidden="true"></i> Borrar</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="container-fluid">
<div class="row">
<div class="col-md-9">
<div class="card">
<div class="card-header">
<h2>Historias</h2>
</div>
<div class="card-body">
<a href="{{ url('/Historial/create') }}" class="btn btn-success btn-sm" title="Add New Student">
<i class="fa fa-plus" aria-hidden="true"></i> Nueva Historia
</a>
<br/>
<br/>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Persona</th>
<th>Sede</th>
<th>Medico</th>
<th>Fecha del Historial</th>
<th>Detalles de la Historia </th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
@foreach ($Historias as $Historia)
<tr>
<td>{{ $Historia->personas->nombre_per ." ".$Historia->personas->apellido_pa_per ." ".$Historia->personas->apellido_ma_per }}</td>
<td>{{ $Historia->sede->nombre_sede }}</td>
<td>{{ $Historia->users->persona->nombre_per ." ". $Historia->users->persona->apellido_pa_per ." ". $Historia->users->persona->apellido_ma_per}}</td>
<td>{{ $Historia->fecha_historial}}</td>
<td>{{ $Historia->detalles_historial }}</td>
<td>
<a href="{{ url('/Historial' . '/' . $Historia['id_historial']) }}" title="View Student"><button class="btn btn-info btn-sm"><i class="fa fa-eye" aria-hidden="true"></i> Mostrar</button></a>
<a href="{{ url('/Historial' . '/' . $Historia->id_historial . '/edit') }}" title="Edit Student"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Editar</button></a>
<form method="POST" action="{{ url('/Historial' . '/' . $Historia->id_historial) }}" accept-charset="UTF-8" style="display:inline">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger btn-sm" title="Delete Student" onclick="return confirm(&quot;Confirm delete?&quot;)"><i class="fa fa-trash-o" aria-hidden="true"></i> Borrar</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

</x-layouts.app>
40 changes: 30 additions & 10 deletions resources/views/admin/user/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,37 @@
<div class="card-body">
<form action="{{ url('Usuario') }}" method="post">
{!! csrf_field() !!}
<label>Usuario</label></br>
<input type="text" name="id" id="id" class="form-control"></br>

<label>Nombre</label></br>
<input type="text" name="name" id="name" class="form-control"></br>

<label>Nombre Usuario</label></br>
<input type="text" name="username" id="username" class="form-control"></br>

<label>Estado</label></br>
<input type="text" name="estado" id="estado" class="form-control"></br>
<label>Nombres</label></br>
<input type="text" name="nombre_per" class="form-control"></br>
<label>Apellido Paterno</label></br>
<input type="text" name="apellido_pa_per" class="form-control"></br>
<label>Apellido Materno</label></br>
<input type="text" name="apellido_ma_per" class="form-control"></br>
<label>Carnet de Identidad</label></br>
<input type="number" name="ci_per" class="form-control"></br>
<label>Celular</label></br>
<input type="tel" name="cel_per" class="form-control"></br>
<label>Fecha Nacimiento</label></br>
<input type="date" name="fecha_nac" class="form-control"></br>
<label>Numero de Seguro</label></br>
<input type="number" name="num_seguro" class="form-control"></br>
<label>Tipo de Sangre</label></br>
<select class="form-control" name="id_tipo_sangre">
@foreach($tipos_sangre as $tipo_sangre)
<option value="{{ $tipo_sangre->id_tipo_sangre }}">{{$tipo_sangre->nombre_tipo_sangre}}</option>
@endforeach
</select> <br>
<label>Pariente Donante</label></br>
<select class="form-control" name="id_pariente">
@foreach($personas as $persona)
<option value="{{ $persona->id_persona }}">{{$persona->nombre_per}}</option>
@endforeach
</select> <br>
<label>Es donante</label></br>
<input type="text" name="donante" class="form-control"></br>
<label>Usuario</label></br>
<input type="text" name="username" id="id" class="form-control"></br>

<label>Email</label></br>
<input type="text" name="email" id="email" class="form-control"></br>
Expand Down
82 changes: 80 additions & 2 deletions resources/views/admin/user/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
<x-layouts.app>
<x-layouts.app>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Usuarios</h2>
</div>
<div class="card-body">
<a href="{{ url('/Usuario/create') }}" class="btn btn-success btn-sm" title="Añadir nueva usuario">
<i class="fa fa-plus" aria-hidden="true"></i> Nueva Usuario
</a>
<br>
<br>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Nombre</th>
<th>AP</th>
<th>AM</th>
<th>CI</th>
<th>Celular</th>
<th>Fecha Nac</th>
<th># Seguro</th>
<th>Es donante</th>
<th>Tipo Sangre</th>
<th>Pariente</th>
<th>Username</th>
<th>Correo</th>
<th>Acciones</th>
</tr>
</thead>
<tbody>
@foreach ($usuarios as $usuario)
@if ($usuario->estado==1)
<tr>
<td>{{ $usuario->persona->nombre_per }}</td>
<td>{{ $usuario->persona->apellido_pa_per }}</td>
<td>{{ $usuario->persona->apellido_ma_per }}</td>
<td>{{ $usuario->persona->ci_per }}</td>
<td>{{ $usuario->persona->cel_per }}</td>
<td>{{ $usuario->persona->fecha_nac }}</td>
<td>{{ $usuario->persona->num_seguro }}</td>
<td>{{ $usuario->persona->donante }}</td>
<td>{{ $usuario->persona->tipo_sangre->nombre_tipo_sangre }}</td>
<td>{{ $usuario->persona->pariente->nombre_per }}</td>

</x-layouts.app>
<td>{{ $usuario->username }}</td>

<td>{{ $usuario->email }}</td>

<td>
<a href=""
title="Edit Student"><button class="btn btn-primary btn-sm"><i
class="fa fa-pencil-square-o" aria-hidden="true"></i>
Editar</button></a>
<form method="POST" action="{{ url('/Usuario' . '/' . $usuario->id) }}"
accept-charset="UTF-8" style="display:inline">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-danger btn-sm"
title="Delete Student"
onclick="return confirm(&quot;Confirm delete?&quot;)"><i
class="fa fa-trash-o" aria-hidden="true"></i>
Borrar</button>
</form>
</td>
</tr>
@endif

@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</x-layouts.app>
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Http\Controllers\PersonaController;

use App\Http\Controllers\HistorialController;
use App\Http\Controllers\UsuarioController;
/*
|--------------------------------------------------------------------------
| Web Routes
Expand Down Expand Up @@ -48,4 +49,5 @@
Route::resource('Historial', HistorialController::class);
Route::resource('TipoRelacion', \App\Http\Controllers\TipoRelacionController::class);
Route::resource('Citas', CitasController::class);
Route::resource('Usuario', UsuarioController::class);

0 comments on commit f39cf03

Please sign in to comment.