diff --git a/app/Http/Controllers/HistorialController.php b/app/Http/Controllers/HistorialController.php index 86d4677..444dd4a 100644 --- a/app/Http/Controllers/HistorialController.php +++ b/app/Http/Controllers/HistorialController.php @@ -3,6 +3,10 @@ namespace App\Http\Controllers; use App\Models\Historial; + +use App\Models\Sede; +use App\Models\User; +use App\Models\Persona; use Illuminate\Http\Request; class HistorialController extends Controller @@ -11,14 +15,21 @@ class HistorialController extends Controller public function index() { // - $Historias = Historial::all(); + $Historias = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->get(); return view('admin.Historial.index',compact('Historias')); + + //return $Historias; } public function create() { // - return view('admin.Historial.create'); + $Sedes = Sede::all(); + $Users = User::with('persona')->get(); + + return view('admin.Historial.create',compact('Sedes','Users')); + + //return $Users; } public function store(Request $request) @@ -32,20 +43,30 @@ public function store(Request $request) } - public function show(Historial $Historial) + public function show($Historial) { // $Historia= Historial::find($Historial); + $Historial = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->find($Historial); + return View ('admin.Historial.show',compact('Historial')); + // + } - public function edit($historial) + public function edit($Historial) { // - $Historia= Historial::find($historial); - return View ('admin.Historial.edit',compact('Historia')); + $Sedes = Sede::all(); + $Users = User::with('persona')->get(); + $Historia = Historial::with(['personas:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','users.persona:id_persona,nombre_per,apellido_pa_per,apellido_ma_per','sede:id_sede,nombre_sede'])->find($Historial); + + return View ('admin.Historial.edit',compact('Historia','Sedes','Users')); + + //return $Historia; + } diff --git a/app/Models/Historial.php b/app/Models/Historial.php index 66aaa09..b7fe245 100644 --- a/app/Models/Historial.php +++ b/app/Models/Historial.php @@ -12,4 +12,20 @@ class Historial extends Model protected $table = 'historial'; protected $primaryKey = 'id_historial'; protected $fillable = ['id_persona','id_sede','id_medico','fecha_historial','detalles_historial']; + public function personas() + { + return $this->belongsTo(Persona::class,'id_persona'); + } + + public function users() + { + return $this->belongsTo(User::class,'id_medico'); + } + + public function sede() + { + return $this->belongsTo(Sede::class,'id_sede'); + } + + } diff --git a/app/Models/User.php b/app/Models/User.php index 7ac239b..6665665 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -43,4 +43,8 @@ class User extends Authenticatable protected $casts = [ 'email_verified_at' => 'datetime', ]; + public function persona() + { + return $this->belongsTo(Persona::class,'id_persona','id_persona'); + } } diff --git a/resources/views/admin/Historial/create.blade.php b/resources/views/admin/Historial/create.blade.php index e325ee8..d00ca50 100644 --- a/resources/views/admin/Historial/create.blade.php +++ b/resources/views/admin/Historial/create.blade.php @@ -5,29 +5,52 @@
Registro de Historias
-
+ {!! csrf_field() !!} -
-
-
-
-
-
+ {{--
+
--}} -
-
+

+ + @foreach ( $Users as $user) + @if ($user->rol == 2 ) + + + @endif + @endforeach + + + + +
- {{--
- --}} + +
+ +
+
+ +
+

@@ -35,5 +58,4 @@
- diff --git a/resources/views/admin/Historial/edit.blade.php b/resources/views/admin/Historial/edit.blade.php index 75c1bf3..1fa554b 100644 --- a/resources/views/admin/Historial/edit.blade.php +++ b/resources/views/admin/Historial/edit.blade.php @@ -4,25 +4,58 @@
Editar Sede
-
+ {!! csrf_field() !!} @method("PATCH") -
-
-
-
-
-
+

+ + @foreach ( $Users as $user) + @if ($user->rol == 2 ) + @if ($user->persona->id_persona == $Historia->personas->id_persona) + + @else + + @endif + @endif + @endforeach + + + +
-
-
+
+ +
+
+ +
+

diff --git a/resources/views/admin/Historial/index.blade.php b/resources/views/admin/Historial/index.blade.php index dd5626c..c3fb968 100644 --- a/resources/views/admin/Historial/index.blade.php +++ b/resources/views/admin/Historial/index.blade.php @@ -28,12 +28,11 @@ @foreach ($Historias as $Historia) - - {{ $Historia['id_persona'] }} - {{ $Historia['id_sede'] }} - {{ $Historia['id_medico'] }} - {{ $Historia['fecha_historial'] }} - {{ $Historia['detalles_historial'] }} + {{ $Historia->personas->nombre_per ." ".$Historia->personas->apellido_pa_per ." ".$Historia->personas->apellido_ma_per }} + {{ $Historia->sede->nombre_sede }} + {{ $Historia->users->persona->nombre_per ." ". $Historia->users->persona->apellido_pa_per ." ". $Historia->users->persona->apellido_ma_per}} + {{ $Historia->fecha_historial}} + {{ $Historia->detalles_historial }}
diff --git a/resources/views/admin/Historial/show.blade.php b/resources/views/admin/Historial/show.blade.php index 27117f4..5fa0c33 100644 --- a/resources/views/admin/Historial/show.blade.php +++ b/resources/views/admin/Historial/show.blade.php @@ -4,9 +4,10 @@
-
Nombre de la Persona: {{ $Historial->id_persona }}
-

Nombre de la Sede : {{ $Historial->id_sede }}

-

Nombre del Medico : {{ $Historial->id_medico }}

+
Datos de la Historia
+

Nombre de la Persona: {{ $Historial->personas->nombre_per ." ".$Historial->personas->apellido_pa_per ." ".$Historial->personas->apellido_ma_per }}

+

Nombre de la Sede : {{ $Historial->sede->nombre_sede }}

+

Nombre del Medico : {{ $Historial->users->persona->nombre_per ." ". $Historial->users->persona->apellido_pa_per ." ". $Historial->users->persona->apellido_ma_per }}

Fecha del Historial: {{ $Historial->fecha_historial }}

Detalles de la Historia: {{ $Historial->detalles_historial }}