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

Commit

Permalink
Mejoras en crud persona con sus relaciones asi como elcrud tipo relac…
Browse files Browse the repository at this point in the history
…iones
  • Loading branch information
rats4final committed Nov 24, 2022
1 parent 7530eaa commit a7d52e3
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 21 deletions.
6 changes: 5 additions & 1 deletion app/Http/Controllers/PersonaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

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

Expand All @@ -16,6 +17,7 @@ class PersonaController extends Controller
public function index()
{
$personas = Persona::get();
//return $personas;
return view('admin.Persona.index', compact('personas'));
}

Expand All @@ -26,7 +28,9 @@ public function index()
*/
public function create()
{
return view('admin.Persona.create');
$personas = Persona::get();
$tipos_sangre = TipoSangre::get();
return view('admin.Persona.create', compact('tipos_sangre','personas'));
}

/**
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/TipoRelacionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Models\Persona;
use App\Models\TipoRelacion;
use Illuminate\Http\Request;

Expand All @@ -15,6 +16,7 @@ class TipoRelacionController extends Controller
public function index()
{
$TipoRelaciones = TipoRelacion::get();
//return $TipoRelaciones;
return view('admin.tipo_relacion.index', compact('TipoRelaciones'));
}

Expand All @@ -25,7 +27,8 @@ public function index()
*/
public function create()
{
return view('admin.tipo_relacion.create');
$personas = Persona::get();
return view('admin.tipo_relacion.create', compact('personas'));
}

/**
Expand Down
11 changes: 10 additions & 1 deletion app/Models/Persona.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ class Persona extends Model
'fecha_nac',
'num_seguro',
'donante',
'id_tipo_sangre'
'id_tipo_sangre',
'id_pariente'
];
protected $dates = [
'fecha_nac'
];

public function tipo_sangre(){
return $this->belongsTo(TipoSangre::class,'id_tipo_sangre','id_tipo_sangre');
}

public function pariente(){
return $this->belongsTo(Persona::class,'id_pariente','id_persona');
}

}
2 changes: 1 addition & 1 deletion app/Models/TipoSangre.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TipoSangre extends Model
{
use HasFactory;

protected $table = 'tipo_sangre';
protected $table = 'tipos_sangre';
protected $primaryKey = 'id_tipo_sangre';
protected $fillable = ['nombre_tipo_sangre','descripcion_tipo_sangre','rareza_tipo_sangre'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
public function up()
{

Schema::create('tipos_sangre', function (Blueprint $table) {
$table->increments('id_tipo_sangre');
$table->string('nombre_tipo_sangre')->unique();
Expand Down
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 @@ -25,6 +25,8 @@ public function up()
$table->date('fecha_nac');
$table->Integer('id_tipo_sangre')->unsigned();
$table->foreign('id_tipo_sangre')->references('id_tipo_sangre')->on('tipos_sangre');
$table->integer('id_pariente')->unsigned()->nullable();
$table->foreign('id_pariente')->references('id_persona')->on('personas');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public function up()
{
Schema::create('tipo_relacion', function (Blueprint $table) {
$table->increments('id_tipo_rel');
$table->increments('id_tipo_relacion');
$table->string('relacion');
$table->Integer('id_persona')->unsigned();
$table->foreign('id_persona')->references('id_persona')->on('personas');
Expand Down
22 changes: 16 additions & 6 deletions resources/views/admin/Persona/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@
<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>
<input type="number" name="ci_per" class="form-control"></br>
<label>Celular</label></br>
<input type="text" name="cel_per" class="form-control"></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="text" name="num_seguro" class="form-control"></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>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>
<input type="submit" value="Guardar" class="btn btn-success"></br>
</form>

</div>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/admin/Persona/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<th># Seguro</th>
<th>Es donante</th>
<th>Tipo Sangre</th>
<th>Pariente</th>
<th>Acciones</th>
</tr>
</thead>
Expand All @@ -40,6 +41,7 @@
<td>{{ $persona->num_seguro }}</td>
<td>{{ $persona->donante }}</td>
<td>{{ $persona->tipo_sangre->nombre_tipo_sangre }}</td>
<td>{{ $persona->pariente->nombre_per }}</td>
<td>
<a href="{{ route('personas.show', $persona) }}"
title="View Student"><button class="btn btn-info btn-sm"><i
Expand Down
6 changes: 1 addition & 5 deletions resources/views/admin/Sedes/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<x-layouts.app>

<div class="container">
<div class="row">
<div class="d-flex">
<div class="col-md-9">
<div class="card">
<div class="card-header">
Expand Down Expand Up @@ -48,7 +46,5 @@
</div>
</div>
</div>
</div>
</div>

</x-layouts.app>
21 changes: 17 additions & 4 deletions resources/views/admin/tipo_relacion/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@
<form action="{{ route('TipoRelacion.store') }}" method="post">
@csrf
<label>Relacion</label></br>
<input type="text" name="relacion" class="form-control"></br>
<select class="form-control" name="relacion">
<option>Padre</option>
<option>Madre</option>
<option>Hermano(a)</option>
<option>Tio(a)</option>
</select>
<label>Persona 1</label></br>
<input type="text" name="id_persona" class="form-control"></br>
<select class="form-control" name="id_persona">
@foreach($personas as $persona)
<option value="{{$persona->id_persona}}">{{$persona->nombre_per}}</option>
@endforeach
</select>
<label>Persona 2</label></br>
<input type="text" name="id_pariente" class="form-control"></br>
<input type="submit" value="Save" class="btn btn-success"></br>
<select class="form-control" name="id_pariente">
@foreach($personas as $pariente)
<option value="{{$pariente->id_persona}}">{{$pariente->nombre_per}}</option>
@endforeach
</select><br>
<input type="submit" value="Guardar" class="btn btn-success"></br>
</form>
</div>
</div>
Expand Down

0 comments on commit a7d52e3

Please sign in to comment.