Agrego Crear y Editar personas
This commit is contained in:
parent
dcd29db524
commit
8bd197dd42
|
|
@ -7,14 +7,74 @@ use App\Models\Persona;
|
|||
|
||||
class PersonaController extends Controller
|
||||
{
|
||||
public function index(Request $request){
|
||||
public function index()
|
||||
{
|
||||
$personas = Persona::all();
|
||||
return view('personas.index', ["personas" => $personas]);
|
||||
|
||||
return view('personas.index', [
|
||||
"personas" => $personas
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id){
|
||||
public function show($id)
|
||||
{
|
||||
$persona = Persona::findOrFail($id);
|
||||
|
||||
return view('personas.show', [
|
||||
"persona" => $persona
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('personas.new');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$persona = new Persona();
|
||||
|
||||
$persona->fill([
|
||||
'nombre' => $request->input('nombre'),
|
||||
'apellido' => $request->input('apellido'),
|
||||
'dni' => $request->input('dni'),
|
||||
]);
|
||||
|
||||
$persona->save();
|
||||
|
||||
return redirect('/personas');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$persona = Persona::findOrFail($id);
|
||||
|
||||
return view('personas.edit', [
|
||||
"persona" => $persona
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$persona = Persona::findOrFail($id);
|
||||
|
||||
$persona->fill([
|
||||
'nombre' => $request->input('nombre'),
|
||||
'apellido' => $request->input('apellido'),
|
||||
'dni' => $request->input('dni'),
|
||||
]);
|
||||
|
||||
$persona->update();
|
||||
|
||||
return redirect('/personas');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$persona = Persona::findOrFail($id);
|
||||
|
||||
$persona->delete();
|
||||
|
||||
return redirect('/personas');
|
||||
}
|
||||
}
|
||||
|
|
@ -5,19 +5,20 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class persona extends Model
|
||||
class Persona extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'Persona';
|
||||
protected $table = 'personas';
|
||||
|
||||
public $primarykey = 'id_persona';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
public $timestamps = false;
|
||||
protected $fillable = [
|
||||
'apellido',
|
||||
'nombre',
|
||||
'dni',
|
||||
];
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = [
|
||||
'nombre',
|
||||
'apellido',
|
||||
'dni',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
48
resources/views/personas/edit.blade.php
Normal file
48
resources/views/personas/edit.blade.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<!doctype html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Editar Persona</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Editar Persona</h1>
|
||||
|
||||
<form method="POST"
|
||||
action="{{ route('personas.update', $persona->id) }}">
|
||||
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<p>
|
||||
Nombre:
|
||||
<input type="text"
|
||||
name="nombre"
|
||||
value="{{ $persona->nombre }}">
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Apellido:
|
||||
<input type="text"
|
||||
name="apellido"
|
||||
value="{{ $persona->apellido }}">
|
||||
</p>
|
||||
|
||||
<p>
|
||||
DNI:
|
||||
<input type="text"
|
||||
name="dni"
|
||||
value="{{ $persona->dni }}">
|
||||
</p>
|
||||
|
||||
<button type="submit">
|
||||
Guardar Cambios
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -1,28 +1,68 @@
|
|||
<!doctype html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<title>Persona</title>
|
||||
<meta charset="utf-8">
|
||||
<title>Personas</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<ul>
|
||||
@foreach($personas as $cat)
|
||||
<li>
|
||||
<strong>{{ $cat->apellido }}</strong>
|
||||
— {{ $cat->nombre }}
|
||||
(DNI: {{ $cat->dni }})
|
||||
<h1>Listado de Personas</h1>
|
||||
|
||||
<form action="{{ route('persona.destroy', $cat->id) }}" method="POST">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button onclick="return confirm('¿Eliminar esta persona?')">
|
||||
Eliminar
|
||||
</button>
|
||||
</form>
|
||||
<p>
|
||||
<a href="{{ route('personas.create') }}">
|
||||
Nueva Persona
|
||||
</a>
|
||||
</p>
|
||||
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
<ul>
|
||||
|
||||
@foreach($personas as $cat)
|
||||
|
||||
<li>
|
||||
|
||||
<strong>{{ $cat->nombre }}</strong>
|
||||
|
||||
- {{ $cat->apellido }}
|
||||
|
||||
- {{ $cat->dni }}
|
||||
|
||||
(ID: {{ $cat->id }})
|
||||
|
||||
|
|
||||
|
||||
<a href="{{ route('personas.show', $cat->id) }}">
|
||||
Ver Más
|
||||
</a>
|
||||
|
||||
|
|
||||
|
||||
<a href="{{ route('personas.edit', $cat->id) }}">
|
||||
Editar
|
||||
</a>
|
||||
|
||||
|
|
||||
|
||||
<form action="{{ route('personas.destroy', $cat->id) }}"
|
||||
method="POST"
|
||||
style="display:inline;">
|
||||
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
|
||||
<button type="submit">
|
||||
Eliminar
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</li>
|
||||
|
||||
@endforeach
|
||||
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
58
resources/views/personas/new.blade.php
Normal file
58
resources/views/personas/new.blade.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<!doctype html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Nueva Persona</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Nueva Persona</h1>
|
||||
|
||||
<form method="POST"
|
||||
action="{{ route('personas.store') }}">
|
||||
|
||||
@csrf
|
||||
|
||||
<div>
|
||||
<label>Nombre</label><br>
|
||||
|
||||
<input type="text"
|
||||
name="nombre"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px;">
|
||||
<label>Apellido</label><br>
|
||||
|
||||
<input type="text"
|
||||
name="apellido"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px;">
|
||||
<label>DNI</label><br>
|
||||
|
||||
<input type="text"
|
||||
name="dni"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div style="margin-top:15px;">
|
||||
|
||||
<button type="submit">
|
||||
Guardar
|
||||
</button>
|
||||
|
||||
<a href="{{ route('personas.index') }}">
|
||||
Volver
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
47
resources/views/personas/show.blade.php
Normal file
47
resources/views/personas/show.blade.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<!doctype html>
|
||||
<html lang="es">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ver Persona</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h1>Ver Persona</h1>
|
||||
|
||||
<div>
|
||||
<label>Nombre</label><br>
|
||||
|
||||
<input type="text"
|
||||
readonly
|
||||
value="{{ $persona->nombre }}">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px;">
|
||||
<label>Apellido</label><br>
|
||||
|
||||
<input type="text"
|
||||
readonly
|
||||
value="{{ $persona->apellido }}">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:10px;">
|
||||
<label>DNI</label><br>
|
||||
|
||||
<input type="text"
|
||||
readonly
|
||||
value="{{ $persona->dni }}">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:15px;">
|
||||
|
||||
<a href="{{ route('personas.index') }}">
|
||||
Volver
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -3,10 +3,23 @@
|
|||
use Illuminate\Support\Facades\Route;
|
||||
use App\Http\Controllers\PersonaController;
|
||||
|
||||
Route::get('/', function () {
|
||||
return view('welcome');
|
||||
});
|
||||
Route::get('personas', [PersonaController::class, 'index'])
|
||||
->name('personas.index');
|
||||
|
||||
Route::get('personas', [PersonaController::class, 'index'])->name('persona.index');
|
||||
Route::get('personas/create', [PersonaController::class, 'create'])
|
||||
->name('personas.create');
|
||||
|
||||
Route::delete('personas/{persona}', [PersonaController::class, 'destroy'])->name('persona.destroy');
|
||||
Route::post('personas', [PersonaController::class, 'store'])
|
||||
->name('personas.store');
|
||||
|
||||
Route::get('personas/{persona}', [PersonaController::class, 'show'])
|
||||
->name('personas.show');
|
||||
|
||||
Route::get('personas/edit/{persona}', [PersonaController::class, 'edit'])
|
||||
->name('personas.edit');
|
||||
|
||||
Route::put('personas/update/{persona}', [PersonaController::class, 'update'])
|
||||
->name('personas.update');
|
||||
|
||||
Route::delete('personas/{persona}', [PersonaController::class, 'destroy'])
|
||||
->name('personas.destroy');
|
||||
Loading…
Reference in New Issue
Block a user