Segundo Commit - agrego boton eliminar
This commit is contained in:
parent
b7c9ea8ca5
commit
dcd29db524
|
|
@ -4,15 +4,17 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Models\Persona;
|
use App\Models\Persona;
|
||||||
use App\Http\Controllers\Controller;
|
|
||||||
|
|
||||||
|
|
||||||
class PersonaController extends Controller
|
class PersonaController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request){
|
public function index(Request $request){
|
||||||
$personas= Persona::all();
|
$personas = Persona::all();
|
||||||
dd ($personas);
|
return view('personas.index', ["personas" => $personas]);
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public function destroy(Request $request, $id){
|
||||||
|
$persona = Persona::findOrFail($id);
|
||||||
|
$persona->delete();
|
||||||
|
return redirect('/personas');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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>
|
|
||||||
28
resources/views/personas/index.blade.php
Normal file
28
resources/views/personas/index.blade.php
Normal 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>
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\PersonaController;/*
|
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!
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
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');
|
||||||
Loading…
Reference in New Issue
Block a user