borrado logico y boton restaurar
This commit is contained in:
parent
64ede43cd9
commit
4796d87d81
|
|
@ -3,14 +3,107 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\persona;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use App\Models\Persona;
|
||||
|
||||
class personacontroller extends Controller
|
||||
class PersonaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$personas= Persona::all();
|
||||
$persona = Persona::withTrashed()-> get();
|
||||
|
||||
return view('personas.index',['personas'=>$personas]);
|
||||
return view('personas.index',["personas"=>$persona]);
|
||||
|
||||
// $categorias = Categorias::findOrFail(13);
|
||||
//$cat = Categorias::where('id_categoria', 1)->first();
|
||||
//$categorias = Categorias::where('descripcion', 'Cursos, capacitaciones y formación')->get();
|
||||
//$categorias = Categorias::where('descripcion', 'like', '%Prod%')->get();
|
||||
|
||||
//$categorias = Categorias::orderBy('nombre', 'desc')->get();
|
||||
|
||||
//$categorias = Categorias::first();
|
||||
//$categorias = Categorias::last();
|
||||
/*Categorias::count();*/
|
||||
}
|
||||
public function show($id){
|
||||
$persona = Persona::findOrfail($id);
|
||||
return view('personas.show', ["per"=>$persona]);
|
||||
}
|
||||
|
||||
public function destroy(Request $request, $id){
|
||||
$persona = Persona::findOrfail($id);
|
||||
$persona->delete();
|
||||
return redirect('/personas');
|
||||
}
|
||||
|
||||
|
||||
public function create(){
|
||||
return view('personas.new');
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
|
||||
$persona = new Persona();
|
||||
$persona->fill([
|
||||
'apellido' => $request->input('apellido'),
|
||||
'nombre' => $request->input('nombre'),
|
||||
'dni' => $request->input('dni'),
|
||||
]);
|
||||
$persona->save();
|
||||
return redirect('/personas');
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
$persona = Persona::findOrfail($id);
|
||||
//$categoria = Categorias::where('id_categoria',$id)->first();
|
||||
return view('personas.edit', ["per"=>$persona]);
|
||||
}
|
||||
|
||||
public function update(Request $request, $id){
|
||||
$persona = Persona::findOrfail($id);
|
||||
$persona->fill([
|
||||
'apellido' => $request->input('apellido'),
|
||||
'nombre' => $request->input('nombre'),
|
||||
'dni' => $request->input('dni'),
|
||||
]);
|
||||
$persona->update();
|
||||
return redirect('/personas');
|
||||
}
|
||||
|
||||
public function restaurar(Request $request, $id){
|
||||
$persona = Persona::withTrashed()->findOrfail($id);
|
||||
$persona->restore();
|
||||
return redirect('/personas');
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
|
||||
public function show($id){
|
||||
$categorias = Categorias::findOrfail($id);
|
||||
|
||||
return view('categorias.show', ["cat"=>$categorias]);
|
||||
}
|
||||
|
||||
|
||||
public function edit($id){
|
||||
$categorias = Categorias::findOrfail($id);
|
||||
return view('categorias.edit', ["cat"=>$categorias]);
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id){
|
||||
$categorias = Categorias::findOrfail($id);
|
||||
$categorias->fill([
|
||||
'nombre' => $request->input('nombre'),
|
||||
'descripcion' => $request->input('descripcion'),
|
||||
]);
|
||||
$categorias->update();
|
||||
return redirect('/categorias');
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,18 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class persona extends Model
|
||||
class Persona extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use SoftDeletes;
|
||||
|
||||
protected $table = 'persona';
|
||||
|
||||
public $primaryKey = 'id_persona';
|
||||
|
||||
public $timestamps = false;
|
||||
public $timestamps = true;
|
||||
protected $fillable = [
|
||||
'apellido',
|
||||
'nombre',
|
||||
|
|
|
|||
42
resources/views/personas/edit.blade.php
Normal file
42
resources/views/personas/edit.blade.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<!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>
|
||||
<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) }}">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:12px;">
|
||||
<button type="submit">Guardar</button>
|
||||
<a href="{{ route('personas.index') }}">Volver al listado</a>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -4,17 +4,48 @@
|
|||
<title>Personas</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>
|
||||
<a href="{{ route('personas.create') }}">Nueva persona</a>
|
||||
</p>
|
||||
<ul>
|
||||
@foreach($personas as $per)
|
||||
<li>
|
||||
<strong>{{ $per->apellido }}</strong>
|
||||
— {{ $per->nombre }}
|
||||
{{ $per->dni }}
|
||||
— {{ $per->dni }}
|
||||
(ID: {{ $per->id_persona}})
|
||||
|
|
||||
|
||||
@if($per->trashed())
|
||||
|
||||
<form action="{{ route('personas.restaurar', $per->id_persona) }}"
|
||||
method="POST" >
|
||||
@csrf
|
||||
@method('PUT')
|
||||
<button onclick="return confirm('¿Restaurar esta persona?')">
|
||||
Restaurar persona
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@else
|
||||
<a href="{{ route('personas.show', $per->id_persona) }}">Ver Más</a>
|
||||
|
|
||||
<a href="{{ route('personas.edit', $per->id_persona) }}">Editar </a>
|
||||
<form action="{{ route('personas.destroy', $per->id_persona) }}"
|
||||
method="POST" >
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button onclick="return confirm('¿Eliminar esta persona?')">
|
||||
Eliminar
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{{--<a href="{{ route('personas.edit', $per->id_personas) }}">Editar</a>
|
||||
--}}
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
37
resources/views/personas/new.blade.php
Normal file
37
resources/views/personas/new.blade.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<!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>
|
||||
<label for="nombre">Nombre *</label><br>
|
||||
<input id="nombre" name="nombre" type="text" value="{{ old('nombre') }}" required>
|
||||
</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>
|
||||
37
resources/views/personas/show.blade.php
Normal file
37
resources/views/personas/show.blade.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<!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>Ver persona</h1>
|
||||
|
||||
|
||||
|
||||
<div>
|
||||
<label for="apellido">Apellido *</label><br>
|
||||
<input id="apellido" name="apellido" readonly type="text"
|
||||
value="{{ $per->apellido }}" >
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="nombre">Nombre *</label><br>
|
||||
<input id="nombre" name="nombre" readonly type="text"
|
||||
value="{{ $per->nombre }}" >
|
||||
</div>
|
||||
|
||||
<div style="margin-top:8px;">
|
||||
<label for="dni">DNI</label><br>
|
||||
<input id="dni" readonly name="dni" type="text"
|
||||
value="{{ $per->dni }}">
|
||||
</div>
|
||||
|
||||
<div style="margin-top:12px;">
|
||||
<a href="{{ route('personas.index') }}">Volver al listado</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
<?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('personas.index');
|
||||
|
||||
/*Route::get('personas', [PersonaController::class, 'index'])->name('personas.index');
|
||||
Route::post('personas', [PersonaController::class, 'store'])->name('personas.store');
|
||||
Route::get('personas/create', [PersonaController::class, 'create'])->name('personas.create');
|
||||
Route::get('personas/{persona}', [PersonaController::class, 'show'])->name('personas.show');
|
||||
Route::delete('personas/{persona}', [PersonaController::class, 'destroy'])->name('personas.destroy');
|
||||
Route::get('personas/{persona}/edit', [PersonaController::class, 'edit'])->name('personas.edit');
|
||||
Route::put('personas/{persona}', [PersonaController::class, 'update'])->name('personas.update');*/
|
||||
|
||||
Route::resource('personas', PersonaController::class);
|
||||
Route::put('personas/restaurar/{persona}', [PersonaController::class, 'restaurar'])->name('personas.restaurar');
|
||||
Loading…
Reference in New Issue
Block a user