validaciones y mensajes flash
This commit is contained in:
parent
dc4f2bd7b8
commit
3ac921308e
|
|
@ -1,29 +1,72 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\PersonaModel; // Importación correcta
|
use App\Models\PersonaModel;
|
||||||
|
|
||||||
class PersonaController extends Controller
|
class PersonaController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$personas = PersonaModel::all();
|
$personas = PersonaModel::withTrashed()->get();
|
||||||
return view('personas.index', compact('personas'));
|
return view('personas.index', compact('personas'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function show($id){
|
||||||
|
$personas = PersonaModel::findOrfail($id);
|
||||||
|
return view('personas.show', ["per"=>$personas]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit($id){
|
||||||
|
$personas = PersonaModel::findOrfail($id);
|
||||||
|
return view('personas.edit', ["per"=>$personas]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, $id){
|
||||||
|
$personas = PersonaModel::findOrfail($id);
|
||||||
|
|
||||||
|
$personas->fill([
|
||||||
|
'nombre' => $request->input('nombre'),
|
||||||
|
'apellido' => $request->input('apellido'),
|
||||||
|
'dni' => $request->input('dni'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$personas->update();
|
||||||
|
|
||||||
|
return redirect('/personas');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Request $request, $id){
|
||||||
|
$personas = PersonaModel::findOrfail($id);
|
||||||
|
$personas->delete();
|
||||||
|
|
||||||
|
return redirect('/personas');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(){
|
||||||
|
return view('personas.new');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function store(Request $request){
|
||||||
|
|
||||||
|
$persona = new PersonaModel();
|
||||||
|
|
||||||
|
$persona->fill([
|
||||||
|
'nombre' => $request->input('nombre'),
|
||||||
|
'apellido' => $request->input('apellido'),
|
||||||
|
'dni' => $request->input('dni'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$persona->save();
|
||||||
|
|
||||||
|
return redirect('/personas');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function restaurar(Request $request, $id){
|
||||||
|
$personas = PersonaModel::withTrashed()->findOrfail($id);
|
||||||
|
$personas->restore();
|
||||||
|
$request->session()->flash('mensaje-success', 'La persona fue restaurada.');
|
||||||
|
return redirect('/personas');
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* $persona = Categoria::findOrFail(1);
|
|
||||||
$categorias = Categoria::where('id_categoria', 1)->get();
|
|
||||||
$categorias = Categoria::where('nombre', 'Tecnología')->get();
|
|
||||||
$categorias = Categoria::where('nombre', 'like', '%tec%')->get();
|
|
||||||
$categorias = Categoria::orderBy('nombre', 'asc')->get();
|
|
||||||
$categorias = Categoria::first();
|
|
||||||
$categorias = Categoria::last();
|
|
||||||
Categoria::count();*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
28
app/Http/Requests/StorePersonaRequest.php
Normal file
28
app/Http/Requests/StorePersonaRequest.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StorePersonaRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
40
app/Http/Requests/UdatedPersonaRequest.php
Normal file
40
app/Http/Requests/UdatedPersonaRequest.php
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class UpdatedPersonaRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'nombre' => 'required|regex:/^[a-zA-ZáéíóúñÁÉÍÓÚ]+( [a-zA-ZáéíóúñÁÉÍÓÚ]+)*$/|max:20|unique:personas,nombre,' . $this->route('persona') . ',id_persona',
|
||||||
|
'descripcion' => 'required'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages() {
|
||||||
|
|
||||||
|
return [
|
||||||
|
'nombre.required' => 'el campo nombre es requerido',
|
||||||
|
'nombre.regex' => 'el campo nombre solo debe contener letras',
|
||||||
|
'nombre.max' => 'el campo nombre debe contener un maximo de 20 caracteres',
|
||||||
|
'nombre.unique' => 'ya existe una persona con este nombre',
|
||||||
|
'descripcion' => 'el campo descripcion es requerido'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,12 +4,21 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
class PersonaModel extends Model
|
class PersonaModel extends Model
|
||||||
{
|
{
|
||||||
|
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $table = 'persona'; // nombre de la tabla
|
protected $table = 'persona'; // nombre de la tabla
|
||||||
protected $primaryKey = 'id_persona'; // clave primaria
|
protected $primaryKey = 'id_persona'; // clave primaria
|
||||||
public $timestamps = false;
|
public $timestamps = true;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'nombre',
|
||||||
|
'apellido',
|
||||||
|
'dni',
|
||||||
|
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
resources/views/compartido/errores.blade.php
Normal file
9
resources/views/compartido/errores.blade.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
@if ($errors->any())
|
||||||
|
<div class="alert alert-danger">
|
||||||
|
<ul>
|
||||||
|
@foreach ($errors->all() as $error)
|
||||||
|
<li>{{ $error }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
3
resources/views/compartido/mensajes.blade.php
Normal file
3
resources/views/compartido/mensajes.blade.php
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
@if (session('mensaje-success'))
|
||||||
|
<p class="alert alert-success">{{ session('mensaje-success') }}</p>
|
||||||
|
@endif
|
||||||
126
resources/views/layouts/admin.blade.php
Normal file
126
resources/views/layouts/admin.blade.php
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<!-- viewport => hace que el sitio sea responsive en móviles -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<!-- Token CSRF de Laravel para proteger formularios -->
|
||||||
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||||
|
<!-- yield => permite que cada vista defina su título; si no lo define, se usa "MiApp" -->
|
||||||
|
<title>@yield('title','Sistema Taller')</title>
|
||||||
|
|
||||||
|
<!-- Bootstrap CSS v4.6.2:
|
||||||
|
- framework que da estilos listos para botones, formularios, grillas, etc. -->
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
|
||||||
|
|
||||||
|
<!-- FontAwesome:
|
||||||
|
- librería de íconos (ej: fa-eye, fa-pencil, fa-remove, etc.). -->
|
||||||
|
<link rel="stylesheet"
|
||||||
|
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
|
||||||
|
<!-- DataTables: -->
|
||||||
|
<link rel="stylesheet" href="https://cdn.datatables.net/1.13.8/css/dataTables.bootstrap4.min.css">
|
||||||
|
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/2.4.2/css/buttons.bootstrap4.min.css">
|
||||||
|
<!-- @stack('styles') => permite que otras vistas agreguen CSS extra en esta sección -->
|
||||||
|
@stack('styles')
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- navbar => barra de navegación de Bootstrap -->
|
||||||
|
<!-- navbar-expand-lg => se expande en pantallas grandes (LG) -->
|
||||||
|
<!-- navbar-light => estilo de texto oscuro sobre fondo claro -->
|
||||||
|
<!-- bg-light => fondo gris claro -->
|
||||||
|
|
||||||
|
<nav class="navbar navbar-expand-lg bg-light ">
|
||||||
|
|
||||||
|
<!-- Nombre de la aplicación -->
|
||||||
|
<a class="navbar-brand" href="{{ url('/') }}">
|
||||||
|
MiApp
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- Menú principal -->
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
|
||||||
|
<!-- Personas -->
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
|
||||||
|
<a class="nav-link dropdown-toggle"
|
||||||
|
href="#"
|
||||||
|
data-toggle="dropdown">
|
||||||
|
|
||||||
|
Personas
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="dropdown-menu">
|
||||||
|
|
||||||
|
<a class="dropdown-item"
|
||||||
|
href="{{ route('personas.index') }}">
|
||||||
|
|
||||||
|
Listado
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="dropdown-item"
|
||||||
|
href="{{ route('personas.create') }}">
|
||||||
|
|
||||||
|
Nueva Persona
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<!-- Usuarios -->
|
||||||
|
<li class="nav-item dropdown">
|
||||||
|
|
||||||
|
<a class="nav-link dropdown-toggle"
|
||||||
|
href="#"
|
||||||
|
data-toggle="dropdown">
|
||||||
|
|
||||||
|
Usuarios
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="dropdown-menu">
|
||||||
|
|
||||||
|
<a class="dropdown-item" href="#">
|
||||||
|
Listado
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a class="dropdown-item" href="#">
|
||||||
|
Nuevo Usuario
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</nav>
|
||||||
|
<!-- container => centra el contenido y le da márgenes automáticos laterales -->
|
||||||
|
<!-- py-4 => padding vertical (arriba y abajo) de 1.5rem (~24px) -->
|
||||||
|
<div class="container py-4">
|
||||||
|
<!-- yield('contenido') => espacio donde cada vista Blade inyecta su propio contenido -->
|
||||||
|
@yield('contenido')
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Dependencias JS -->
|
||||||
|
<!-- jQuery => requerido por Bootstrap 4 -->
|
||||||
|
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
|
||||||
|
<!-- Popper.js => requerido para tooltips, dropdowns y menús flotantes -->
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
|
||||||
|
<!-- Bootstrap JS => activa componentes interactivos como modales, menús, tooltips -->
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
|
<!-- DataTables -->
|
||||||
|
<script src="https://cdn.datatables.net/1.13.8/js/jquery.dataTables.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/1.13.8/js/dataTables.bootstrap4.min.js"></script>
|
||||||
|
|
||||||
|
<script src="https://cdn.datatables.net/buttons/2.4.2/js/dataTables.buttons.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.bootstrap4.min.js"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
|
||||||
|
<script src="https://cdn.datatables.net/buttons/2.4.2/js/buttons.html5.min.js"></script>
|
||||||
|
|
||||||
|
<!-- stack('scripts') => permite que otras vistas agreguen scripts extra -->
|
||||||
|
@stack('scripts')
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
86
resources/views/personas/edit.blade.php
Normal file
86
resources/views/personas/edit.blade.php
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
@extends('layouts.admin')
|
||||||
|
@section('contenido')
|
||||||
|
|
||||||
|
<!-- row => fila del sistema de grillas de Bootstrap
|
||||||
|
justify-content-center => centra horizontalmente el contenido dentro de la fila
|
||||||
|
align-items-center => alinea verticalmente los elementos de la fila -->
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<!-- col-lg-11 col-md-11 col-sm-11 col-xs-11 =>
|
||||||
|
la columna ocupa 11/12 partes en todos los tamaños de pantalla -->
|
||||||
|
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11">
|
||||||
|
<h3>Editar Persona</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-10">
|
||||||
|
|
||||||
|
<!-- Includes de Blade para mensajes de éxito y errores -->
|
||||||
|
@include('compartido.mensajes')
|
||||||
|
@include('compartido.errores')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<!-- Formulario de edición de persona -->
|
||||||
|
<form method="POST"
|
||||||
|
action="{{ route('personas.update', $per->id_persona) }}"
|
||||||
|
enctype="multipart/form-data">
|
||||||
|
@csrf
|
||||||
|
@method('PUT') <!-- Indica a Laravel que el método real es PUT -->
|
||||||
|
|
||||||
|
<!-- row => agrupa los campos en una fila -->
|
||||||
|
<div class="row">
|
||||||
|
<!-- form-group => añade márgenes y separación entre los campos -->
|
||||||
|
<!-- col-md-3 => cada campo ocupa 3/12 columnas en pantallas medianas o más grandes -->
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<!-- form-check-label => estilo Bootstrap para etiquetas de formulario -->
|
||||||
|
<label for="nombre" class="form-check-label">Apellido (*)</label>
|
||||||
|
<!-- form-control => da estilo uniforme al input -->
|
||||||
|
<input type="text" name="apellido" id="apellido" class="form-control"
|
||||||
|
value="{{ old('apellido', $per->apellido) }}" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- row => agrupa los campos en una fila -->
|
||||||
|
<!-- form-group => añade márgenes y separación entre los campos -->
|
||||||
|
<!-- col-md-3 => cada campo ocupa 3/12 columnas en pantallas medianas o más grandes -->
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<!-- form-check-label => estilo Bootstrap para etiquetas de formulario -->
|
||||||
|
<label for="nombre" class="form-check-label">Nombre (*)</label>
|
||||||
|
<!-- form-control => da estilo uniforme al input -->
|
||||||
|
<input type="text" name="nombre" id="nombre" class="form-control"
|
||||||
|
value="{{ old('nombre', $per->nombre) }}" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="dni" class="form-check-label">dni (*)</label>
|
||||||
|
<input type="text" name="dni" id="dni" class="form-control"
|
||||||
|
value="{{ old('dni', $per->dni) }}" >
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- row justify-content-center align-items-center =>
|
||||||
|
fila que centra horizontal y verticalmente los botones -->
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn => clase base de Bootstrap para botones
|
||||||
|
btn-success => verde (acción positiva)
|
||||||
|
btn-block => ocupa todo el ancho de la columna
|
||||||
|
btn-lg => tamaño grande -->
|
||||||
|
<button class="btn btn-success btn-block btn-lg">Guardar</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn-primary => azul (acción principal)
|
||||||
|
title="Salir" => tooltip al pasar el mouse -->
|
||||||
|
<a href="{{ route('personas.index') }}" class="btn btn-primary btn-block btn-lg" title="Salir">Salir</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
//Aquí se pueden agregar scripts específicos de esta vista -->
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
41
resources/views/personas/editPlano.blade.php
Normal file
41
resources/views/personas/editPlano.blade.php
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Editar Persona</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Editar Persona</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('personas.update', $per->id_persona) }}">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="apellido">Apellido *</label><br>
|
||||||
|
<input id="apellido" name="apellido" type="text"
|
||||||
|
value="{{ old('apellido', $per->apellido) }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="nombre">Nombre *</label><br>
|
||||||
|
<input id="nombre" name="nombre" type="text"
|
||||||
|
value="{{ old('nombre', $per->nombre) }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="dni">DNI *</label><br>
|
||||||
|
<input id="dni" name="dni" type="text"
|
||||||
|
value="{{ old('dni', $per->dni) }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<button type="submit">Guardar</button>
|
||||||
|
<a href="{{ route('personas.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -1,18 +1,130 @@
|
||||||
<!doctype html>
|
@extends('layouts.admin')
|
||||||
<html lang="es">
|
@section('contenido')
|
||||||
<head>
|
|
||||||
<title>Persona</title>
|
<!-- row => fila del sistema de grillas Bootstrap
|
||||||
</head>
|
justify-content-center => centra horizontalmente los contenidos
|
||||||
<body>
|
align-items-center => centra verticalmente
|
||||||
<ul>
|
no centran el texto, centran las columnas dentro de la fila
|
||||||
@foreach($personas as $per)
|
-->
|
||||||
<li>
|
|
||||||
<strong>{{ $per->apellido }}</strong>
|
<div class="row justify-content-center align-items-center">
|
||||||
<strong>{{ $per->nombre }}</strong>
|
<!-- col-12 => ocupa todo el ancho en pantallas pequeñas
|
||||||
<strong>{{ $per->dni }}</strong>
|
col-md-11 => ocupa 11/12 del ancho en pantallas medianas o mayores -->
|
||||||
(ID: {{ $per->id_persona}})
|
<div class="col-12 col-md-11">
|
||||||
</li>
|
<h3>Listado de Personas</h3>
|
||||||
@endforeach
|
</div>
|
||||||
</ul>
|
</div>
|
||||||
</body>
|
|
||||||
</html>
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn => estilo de botón Bootstrap
|
||||||
|
btn-success => verde (acción positiva)
|
||||||
|
btn-block => ocupa todo el ancho de la columna
|
||||||
|
btn-lg => tamaño grande -->
|
||||||
|
<a href="{{ route('personas.create') }}"
|
||||||
|
class="btn btn-success btn-block btn-lg"
|
||||||
|
title="Nueva Persona">
|
||||||
|
Nuevo
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-12 col-md-11">
|
||||||
|
|
||||||
|
<!-- Includes de Blade para mensajes de éxito y errores -->
|
||||||
|
@include('compartido.mensajes')
|
||||||
|
@include('compartido.errores')
|
||||||
|
|
||||||
|
<!-- table-responsive => hace que la tabla sea "scrollable" en pantallas pequeñas -->
|
||||||
|
<div class="table-responsive">
|
||||||
|
|
||||||
|
<!-- table => tabla con estilos básicos
|
||||||
|
table-striped => filas alternadas con fondo gris
|
||||||
|
table-bordered => agrega bordes a todas las celdas
|
||||||
|
table-hover => resalta la fila al pasar el mouse -->
|
||||||
|
<table class="table table-striped table-bordered table-hover" id="example">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Apellido</th>
|
||||||
|
<th>dni</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($personas as $per)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $per->id_persona }}</td>
|
||||||
|
<td>{{ $per->apellido }}</td>
|
||||||
|
<td>{{ $per->nombre }}</td>
|
||||||
|
<td>{{ $per->dni }}</td>
|
||||||
|
<td align="center">
|
||||||
|
|
||||||
|
@if($per->deleted_at == null)
|
||||||
|
<form method="POST" action="{{ route('personas.destroy', $per->id_persona) }}" style="display:inline;">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
|
||||||
|
<!-- btn-info => azul claro (información) -->
|
||||||
|
<a class="btn btn-info"
|
||||||
|
href="{{ route('personas.show', $per->id_persona) }}"
|
||||||
|
title="Ver más">
|
||||||
|
<i class="fa fa-eye"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- btn-warning => amarillo (advertencia / editar) -->
|
||||||
|
<a class="btn btn-warning"
|
||||||
|
href="{{ route('personas.edit', $per->id_persona) }}"
|
||||||
|
title="Editar">
|
||||||
|
<i class="fa fa-pencil"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- btn-danger => rojo (acción destructiva como eliminar) -->
|
||||||
|
<button class="btn btn-danger"
|
||||||
|
onclick="return confirm('¿Está seguro de eliminar la persona?');"
|
||||||
|
title="Eliminar">
|
||||||
|
<i class="fa fa-remove"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<form method="POST" action="{{ route('personas.restaurar', $per->id_persona) }}" style="display:inline;">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<!-- btn-danger => rojo (acción destructiva como eliminar) -->
|
||||||
|
<button class="btn btn-success"
|
||||||
|
onclick="return confirm('¿Está seguro de Restaurar la persona?');"
|
||||||
|
title="Restaurar">
|
||||||
|
<i class="fa fa-undo"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endif
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
|
@push('styles')
|
||||||
|
|
||||||
|
@endpush
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
// DataTables (plugin JS para mejorar tablas: búsqueda, paginación, exportación)
|
||||||
|
$('#example').DataTable({
|
||||||
|
dom: 'Bfrtip',
|
||||||
|
buttons: ['excel'],
|
||||||
|
pageLength: 5,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
|
|
||||||
52
resources/views/personas/indexPlano.blade.php
Normal file
52
resources/views/personas/indexPlano.blade.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<title>Personas</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
<a href="{{ route('personas.create') }}">Nueva persona</a>
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
@foreach($personas as $persona)
|
||||||
|
<li>
|
||||||
|
<strong>{{ $persona->nombre }}</strong>
|
||||||
|
— {{ $persona->apellido }}
|
||||||
|
— {{ $persona->dni }}
|
||||||
|
(ID: {{ $persona->id_persona }})
|
||||||
|
|
|
||||||
|
@if($persona->deleted_at == null)
|
||||||
|
<a href="{{ route('personas.show', $persona->id_persona) }}">Ver Más</a>
|
||||||
|
|
|
||||||
|
<a href="{{ route('personas.edit', $persona->id_persona) }}">Editar </a>
|
||||||
|
<form action="{{ route('personas.destroy', $persona->id_persona) }}"
|
||||||
|
method="POST" >
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button onclick="return confirm('¿Eliminar esta persona?')">
|
||||||
|
Eliminar
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@else
|
||||||
|
<form action="{{ route('personas.restaurar', $persona->id_persona) }}"
|
||||||
|
method="POST" >
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
<button onclick="return confirm('¿Restaurar esta persona?')">
|
||||||
|
Restaurar
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endif
|
||||||
|
|
||||||
|
{{--<a href="{{ route('personas.edit', $persona->id_persona) }}">Editar</a>
|
||||||
|
--}}
|
||||||
|
|
||||||
|
</li>
|
||||||
|
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
81
resources/views/personas/new.blade.php
Normal file
81
resources/views/personas/new.blade.php
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
@extends('layouts.admin')
|
||||||
|
@section ('contenido')
|
||||||
|
|
||||||
|
<!-- row => fila del sistema de grillas de Bootstrap
|
||||||
|
justify-content-center => centra horizontalmente el contenido dentro de la fila
|
||||||
|
align-items-center => centra verticalmente los elementos dentro de la fila -->
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<!-- col-lg-11 col-md-11 col-sm-11 col-xs-11 =>
|
||||||
|
la columna ocupa 11/12 partes del ancho en todos los tamaños de pantalla -->
|
||||||
|
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11">
|
||||||
|
<h3>Nueva Persona</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-10">
|
||||||
|
|
||||||
|
<!-- Includes de Blade para mensajes de éxito y errores -->
|
||||||
|
@include('compartido.mensajes')
|
||||||
|
@include('compartido.errores')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</br>
|
||||||
|
|
||||||
|
<!-- Formulario para crear nueva persona -->
|
||||||
|
<form method="post" action="{{ route('personas.store') }}" enctype=multipart/form-data>
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<!-- row => agrupa los campos en una fila -->
|
||||||
|
<div class="row">
|
||||||
|
<!-- form-group => separa cada campo del formulario con márgenes
|
||||||
|
col-md-3 => ocupa 3/12 columnas en pantallas medianas hacia arriba -->
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<!-- form-check-label => clase de Bootstrap que estiliza etiquetas de formulario -->
|
||||||
|
<label for="apellido" class="form-check-label">Apellido (*)</label>
|
||||||
|
<!-- form-control => aplica estilos consistentes al input-->
|
||||||
|
<input type="text" name="apellido" id="apellido" value="{{old('apellido')}}" required class="form-control" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- row => agrupa los campos en una fila -->
|
||||||
|
<!-- form-group => separa cada campo del formulario con márgenes
|
||||||
|
col-md-3 => ocupa 3/12 columnas en pantallas medianas hacia arriba -->
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<!-- form-check-label => clase de Bootstrap que estiliza etiquetas de formulario -->
|
||||||
|
<label for="nombre" class="form-check-label">Nombre (*)</label>
|
||||||
|
<!-- form-control => aplica estilos consistentes al input-->
|
||||||
|
<input type="text" name="nombre" id="nombre" value="{{old('nombre')}}" required class="form-control" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="dni" class="form-check-label">dni (*)</label>
|
||||||
|
<input type="text" name="dni" id="dni" value="{{old('dni')}}" required class="form-control">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- row justify-content-center align-items-center =>
|
||||||
|
crea una fila y centra horizontal y verticalmente los botones -->
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn => botón base de Bootstrap
|
||||||
|
btn-success => color verde
|
||||||
|
btn-block => ocupa todo el ancho de la columna
|
||||||
|
btn-lg => tamaño grande -->
|
||||||
|
<button class="btn btn-success btn-block btn-lg">Guardar</button>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn-primary => color azul
|
||||||
|
title="Salir" => muestra tooltip al pasar el mouse -->
|
||||||
|
<a href="{{ route('personas.index') }}" class="btn btn-primary btn-block btn-lg" title="Salir">Salir</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@endsection
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
//Aquí podrías agregar código JavaScript específico para esta vista
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
40
resources/views/personas/newPlano.blade.php
Normal file
40
resources/views/personas/newPlano.blade.php
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Nueva Persona</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Nueva Persona</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('personas.store') }}">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="apellido">Apellido *</label><br>
|
||||||
|
<input id="apellido" name="apellido" type="text"
|
||||||
|
value="{{ old('apellido') }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="nombre">Nombre</label><br>
|
||||||
|
<input id="nombre" name="nombre" type="text"
|
||||||
|
value="{{ old('nombre') }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="dni">DNI</label><br>
|
||||||
|
<input id="dni" name="dni" type="text"
|
||||||
|
value="{{ old('dni') }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<button type="submit">Guardar</button>
|
||||||
|
<a href="{{ route('personas.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
34
resources/views/personas/show.blade.php
Normal file
34
resources/views/personas/show.blade.php
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
@extends('layouts.admin')
|
||||||
|
@section ('contenido')
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-lg-11 col-md-11 col-sm-11 col-xs-11">
|
||||||
|
<h3>Ver Persona</h3>
|
||||||
|
<div class="progress" style="height: 2px;"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</br>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="apellido" class="form-check-label">Apellido (*)</label>
|
||||||
|
<input type="text" name="apellido" id="apellido" class="form-control" value="{{$per->apellido}}" readonly>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="nombre" class="form-check-label">Nombre (*)</label>
|
||||||
|
<input type="text" name="nombre" id="nombre" class="form-control" value="{{$per->nombre}}" readonly>
|
||||||
|
</div>
|
||||||
|
<div class="form-group col-md-3">
|
||||||
|
<label for="dni" class="form-check-label">dni (*)</label>
|
||||||
|
<input type="text" name="dni" id="dni" class="form-control" value="{{$per->dni}}" readonly>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<legend></legend>
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<a href="{{ route('personas.index') }}" class="btn btn-primary btn-block btn-lg" title="Salir">Salir</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
36
resources/views/personas/showPlano.blade.php
Normal file
36
resources/views/personas/showPlano.blade.php
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Ver persona</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Detalle de la persona</h1>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>Apellido:</label><br>
|
||||||
|
<input readonly type="text" value="{{ $per->apellido }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label>Nombre:</label><br>
|
||||||
|
<input readonly type="text" value="{{ $per->nombre }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label>DNI:</label><br>
|
||||||
|
<input readonly type="text" value="{{ $per->dni }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a href="{{ route('personas.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -20,4 +20,14 @@ Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('welcome');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('persona', [PersonaController::class, 'index'])->name('persona.index');
|
/*Route::get('persona', [PersonaController::class, 'index'])->name('personas.index');
|
||||||
|
Route::get('persona/create', [PersonaController::class, 'create'])->name('personas.create');
|
||||||
|
Route::get('persona/{persona}', [PersonaController::class, 'show'])->name('personas.show');
|
||||||
|
Route::get('persona/{persona}/edit', [PersonaController::class, 'edit'])->name('personas.edit');
|
||||||
|
Route::put('persona/{persona}', [PersonaController::class, 'update'])->name('personas.update');
|
||||||
|
Route::delete('persona/{persona}', [PersonaController::class, 'destroy'])->name('personas.destroy');
|
||||||
|
Route::post('persona', [PersonaController::class, 'store'])->name('personas.store');*/
|
||||||
|
Route::put('personas/restaurar/{persona}', [PersonaController::class, 'restaurar'])->name('personas.restaurar');
|
||||||
|
Route::resource('personas', PersonaController::class);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user