Segundo Commit - agrego boton eliminar

This commit is contained in:
Adrian Tejeda 2026-05-06 00:32:44 -03:00
parent b7c9ea8ca5
commit dcd29db524
4 changed files with 41 additions and 37 deletions

View File

@ -4,15 +4,17 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Persona;
use App\Http\Controllers\Controller;
class PersonaController extends Controller
{
public function index(Request $request){
$personas= Persona::all();
dd ($personas);
$personas = Persona::all();
return view('personas.index', ["personas" => $personas]);
}
}
}
public function destroy(Request $request, $id){
$persona = Persona::findOrFail($id);
$persona->delete();
return redirect('/personas');
}
}

View File

@ -1,19 +0,0 @@
<!doctype html>
<html lang="es">
<head>
<title>Persona</title>
</head>
<body>
<ul>
@foreach($personas as $cat)
<li>
<strong>{{ $cat->apellido }}</strong>
{{ $cat->nombre }}
(ID: {{ $cat->dni}})
</li>
@endforeach
</ul>
</body>
</html>

View File

@ -0,0 +1,28 @@
<!doctype html>
<html lang="es">
<head>
<title>Persona</title>
</head>
<body>
<ul>
@foreach($personas as $cat)
<li>
<strong>{{ $cat->apellido }}</strong>
{{ $cat->nombre }}
(DNI: {{ $cat->dni }})
<form action="{{ route('persona.destroy', $cat->id) }}" method="POST">
@csrf
@method('DELETE')
<button onclick="return confirm('¿Eliminar esta persona?')">
Eliminar
</button>
</form>
</li>
@endforeach
</ul>
</body>
</html>

View File

@ -1,19 +1,12 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PersonaController;/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
use App\Http\Controllers\PersonaController;
Route::get('/', function () {
return view('welcome');
});
Route :: get('personas', [PersonaController::class, 'index'])->name('persona.index');
Route::get('personas', [PersonaController::class, 'index'])->name('persona.index');
Route::delete('personas/{persona}', [PersonaController::class, 'destroy'])->name('persona.destroy');