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

Commit

Permalink
CRUD Personas sin relacion
Browse files Browse the repository at this point in the history
  • Loading branch information
rats4final committed Nov 10, 2022
1 parent bd9edb7 commit cae896f
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 0 deletions.
92 changes: 92 additions & 0 deletions app/Http/Controllers/PersonaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Http\Controllers;

use App\Models\Persona;
use Illuminate\Http\Request;
use Psy\CodeCleaner\ReturnTypePass;

class PersonaController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$personas = Persona::get();
return view('admin.Persona.index', compact('personas'));
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.Persona.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$datos = $request->all();
Persona::create($datos);
return to_route('personas.index');
}

/**
* Display the specified resource.
*
* @param \App\Models\Persona $persona
* @return \Illuminate\Http\Response
*/
public function show(Persona $persona)
{
return view('admin.Persona.show', compact('persona'));
}

/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Persona $persona
* @return \Illuminate\Http\Response
*/
public function edit(Persona $persona)
{
return view('admin.Persona.edit', compact('persona'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Persona $persona
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Persona $persona)
{
$datos = $request->all();
$persona->update($datos);
return to_route('personas.index');
}

/**
* Remove the specified resource from storage.
*
* @param \App\Models\Persona $persona
* @return \Illuminate\Http\Response
*/
public function destroy(Persona $persona)
{
$persona->delete();
return to_route('personas.index');
}
}
24 changes: 24 additions & 0 deletions app/Models/Persona.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Persona extends Model
{
use HasFactory;
protected $primaryKey = 'id_persona';
protected $table = 'personas';
protected $fillable = [
'nombre_per',
'apellido_pa_per',
'apellido_ma_per',
'ci_per',
'cel_per',
'fecha_nac',
'num_seguro',
'donante',
'id_tipo_sangre'
];
}
2 changes: 2 additions & 0 deletions database/migrations/2022_09_22_152240_create_personas.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function up()
$table->string('apellido_ma_per');
$table->integer('ci_per');
$table->integer('cel_per');
$table->string('num_seguro');
$table->boolean('donante');
$table->date('fecha_nac');
$table->Integer('id_tipo_sangre')->unsigned();
$table->foreign('id_tipo_sangre')->references('id_tipo_sangre')->on('tipo_sangre');
Expand Down
31 changes: 31 additions & 0 deletions resources/views/admin/Persona/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<x-layouts.app>
<div class="card">
<div class="card-header">Registro de Personas</div>
<div class="card-body">

<form action="{{ route('personas.store') }}" method="post">
@csrf
<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="text" name="ci_per" class="form-control"></br>
<label>Celular</label></br>
<input type="text" 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="text" name="num_seguro" class="form-control"></br>
<label>Es donante</label></br>
<input type="text" name="donante" class="form-control"></br>
<label>Tipo de Sangre</label></br>
<input type="text" name="id_tipo_sangre" class="form-control"></br>
<input type="submit" value="Save" class="btn btn-success"></br>
</form>

</div>
</div>
</x-layouts.app>
32 changes: 32 additions & 0 deletions resources/views/admin/Persona/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<x-layouts.app>
<div class="card">
<div class="card-header">Registro de Personas</div>
<div class="card-body">

<form action="{{ route('personas.update', $persona) }}" method="post">
@csrf
@method('PATCH')
<label>Nombres</label></br>
<input value="{{ $persona->nombre_per }}" type="text" name="nombre_per" class="form-control"></br>
<label>Apellido Paterno</label></br>
<input value="{{ $persona->apellido_pa_per }}" type="text" name="apellido_pa_per" class="form-control"></br>
<label>Apellido Materno</label></br>
<input value="{{ $persona->apellido_ma_per }}" type="text" name="apellido_ma_per" class="form-control"></br>
<label>Carnet de Identidad</label></br>
<input value="{{ $persona->ci_per }}" type="text" name="ci_per" class="form-control"></br>
<label>Celular</label></br>
<input value="{{ $persona->cel_per }}" type="text" name="cel_per" class="form-control"></br>
<label>Fecha Nacimiento</label></br>
<input value="{{ $persona->fecha_nac }}" type="date" name="fecha_nac" class="form-control"></br>
<label>Numero de Seguro</label></br>
<input value="{{ $persona->num_seguro }}" type="text" name="num_seguro" class="form-control"></br>
<label>Es donante</label></br>
<input value="{{ $persona->donante }}" type="text" name="donante" class="form-control"></br>
<label>Tipo de Sangre</label></br>
<input value="{{ $persona->id_tipo_sangre }}" type="text" name="id_tipo_sangre" class="form-control"></br>
<input type="submit" value="Save" class="btn btn-success"></br>
</form>
</div>
</div>
</x-layouts.app>

73 changes: 73 additions & 0 deletions resources/views/admin/Persona/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<x-layouts.app>
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="card">
<div class="card-header">
<h2>Personas</h2>
</div>
<div class="card-body">
<a href="{{ route('personas.create') }}" class="btn btn-success btn-sm" title="Añadir nueva Persona">
<i class="fa fa-plus" aria-hidden="true"></i> Nueva Persona
</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>Acciones</th>
</tr>
</thead>
<tbody>
@foreach ($personas as $persona)
<tr>
<td>{{ $persona->nombre_per }}</td>
<td>{{ $persona->apellido_pa_per }}</td>
<td>{{ $persona->apellido_ma_per }}</td>
<td>{{ $persona->ci_per }}</td>
<td>{{ $persona->cel_per }}</td>
<td>{{ $persona->fecha_nac }}</td>
<td>{{ $persona->num_seguro }}</td>
<td>{{ $persona->donante }}</td>
<td>{{ $persona->id_tipo_sangre }}</td>
<td>
<a href="{{ route('personas.show', $persona) }}"
title="View Student"><button class="btn btn-info btn-sm"><i
class="fa fa-eye" aria-hidden="true"></i>
Mostrar</button></a>
<a href="{{ route('personas.edit', $persona) }}"
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="{{ route('personas.destroy', $persona) }}"
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>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</x-layouts.app>
19 changes: 19 additions & 0 deletions resources/views/admin/Persona/show.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<x-layouts.app>
<div class="card">
<div class="card-header">Datos de la Persona</div>
<div class="card-body">
<div class="card-body">
<h5 class="card-title">Nombres : {{ $persona->nombre_per }}</h5>
<p class="card-text">Apellido Paterno: {{ $persona->apellido_pa_per }}</p>
<p class="card-text">Apellido Materno : {{ $persona->apellido_ma_per }}</p>
<p class="card-text">Carnet de Identidad: {{ $persona->ci_per }}</p>
<p class="card-text">Celular: {{ $persona->cel_per }}</p>
<p class="card-text">Fecha de Nacimiento: {{ $persona->fecha_nac }}</p>
<p class="card-text">Numero de Seguro: {{ $persona->num_seguro }}</p>
<p class="card-text">Es donante: {{ $persona->donante }}</p>
<p class="card-text">Tipo de Sangre: {{ $persona->id_tipo_sangre }}</p>
</div>
</hr>
</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 @@ -6,6 +6,7 @@
use App\Models\TipoPatologia;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PatologiaController;
use App\Http\Controllers\PersonaController;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -41,3 +42,4 @@
Route::resource('TipoSangre', TipoSangreController::class);
Route::resource('TipoPatologia', TipoPatologiaController::class);
Route::resource('Patologia', PatologiaController::class);
Route::resource('personas', PersonaController::class);

0 comments on commit cae896f

Please sign in to comment.