mostrar categoria
This commit is contained in:
parent
24f777ce9a
commit
6a5ac55b2e
|
|
@ -27,6 +27,57 @@ class CategoriasController extends Controller
|
||||||
|
|
||||||
return view('categorias.index', ["categorias"=>$categorias]);
|
return view('categorias.index', ["categorias"=>$categorias]);
|
||||||
}
|
}
|
||||||
|
public function show($id){
|
||||||
|
$categoria = Categorias::findOrfail($id);
|
||||||
|
return view('categorias.show', ["cat"=>$categoria]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public function create(){
|
||||||
|
return view('categorias.new');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function store(Request $request){
|
||||||
|
$categorias = new Categorias();
|
||||||
|
$categorias->fill([
|
||||||
|
'nombre' => $request->input('nombre'),
|
||||||
|
'descripcion' => $request->input('descripcion'),
|
||||||
|
]);
|
||||||
|
$categorias->save();
|
||||||
|
return redirect('/categorias');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function destroy(Request $request, $id){
|
||||||
|
$categorias = Categorias::findOrfail($id);
|
||||||
|
$categorias->delete();
|
||||||
|
return redirect('/categorias');
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
35
resources/views/categorias/edit.blade.php
Normal file
35
resources/views/categorias/edit.blade.php
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Editar categoría</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Editar categoría</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('categorias.update', $cat->id_categoria) }}">
|
||||||
|
@csrf
|
||||||
|
@method('PUT')
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="nombre">Nombre *</label><br>
|
||||||
|
<input id="nombre" name="nombre" type="text"
|
||||||
|
value="{{ old('nombre', $cat->nombre) }}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="descripcion">Descripción</label><br>
|
||||||
|
<input id="descripcion" name="descripcion" type="text"
|
||||||
|
value="{{ old('descripcion', $cat->descripcion) }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<button type="submit">Guardar</button>
|
||||||
|
<a href="{{ route('categorias.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -4,13 +4,33 @@
|
||||||
<title>Categorías</title>
|
<title>Categorías</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<p>
|
||||||
|
{{-- <a href="{{ route('categorias.create') }}">Nueva categoría</a> --}}
|
||||||
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
@foreach($categorias as $cat)
|
@foreach($categorias as $cat)
|
||||||
<li>
|
<li>
|
||||||
<strong>{{ $cat->nombre }}</strong>
|
<strong>{{ $cat->nombre }}</strong>
|
||||||
— {{ $cat->descripcion }}
|
— {{ $cat->descripcion }}
|
||||||
(ID: {{ $cat->id_categoria}})
|
(ID: {{ $cat->id_categoria}})
|
||||||
|
|
|
||||||
|
|
||||||
|
<a href="{{ route('categorias.show', $cat->id_categoria) }}">Ver Más</a>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
{{--<a href="{{ route('categorias.edit', $cat->id_categoria) }}">Editar</a>
|
||||||
|
<form action="{{ route('categorias.destroy', $cat->id_categoria) }}"
|
||||||
|
method="POST" >
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button onclick="return confirm('¿Eliminar esta categoría?')">
|
||||||
|
Eliminar
|
||||||
|
</button>
|
||||||
|
</form>--}}
|
||||||
</li>
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
32
resources/views/categorias/new.blade.php
Normal file
32
resources/views/categorias/new.blade.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Nueva categoría</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Nueva categoría</h1>
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('categorias.store') }}">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<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="descripcion">Descripción</label><br>
|
||||||
|
<input id="descripcion" name="descripcion" type="text" value="{{ old('descripcion') }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<button type="submit">Guardar</button>
|
||||||
|
<a href="{{ route('categorias.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
31
resources/views/categorias/show.blade.php
Normal file
31
resources/views/categorias/show.blade.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="es">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Ver categoría</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<h1>Ver categoría</h1>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="nombre">Nombre *</label><br>
|
||||||
|
<input id="nombre" name="nombre" readonly type="text"
|
||||||
|
value="{{ $cat->nombre }}" >
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:8px;">
|
||||||
|
<label for="descripcion">Descripción</label><br>
|
||||||
|
<input id="descripcion" readonly name="descripcion" type="text"
|
||||||
|
value="{{ $cat->descripcion }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="margin-top:12px;">
|
||||||
|
<a href="{{ route('categorias.index') }}">Volver al listado</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -18,3 +18,15 @@ Route::get('/', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('categorias', [CategoriasController::class, 'index'])->name('categorias.index');
|
Route::get('categorias', [CategoriasController::class, 'index'])->name('categorias.index');
|
||||||
|
Route::get('categorias/{categoria}', [CategoriasController::class, 'show'])->name('categorias.show');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*Route::get('categorias/create', [CategoriasController::class, 'create'])->name('categorias.create');
|
||||||
|
Route::post('categorias', [CategoriasController::class, 'store'])->name('categorias.store');
|
||||||
|
Route::get('categorias/{categoria}', [CategoriasController::class, 'show'])->name('categorias.show');
|
||||||
|
Route::get('categorias/{categoria}/edit', [CategoriasController::class, 'edit'])->name('categorias.edit');
|
||||||
|
Route::match(['put','patch'], 'categorias/{categoria}', [CategoriasController::class, 'update'])->name('categorias.update');
|
||||||
|
Route::delete('categorias/{categoria}', [CategoriasController::class, 'destroy'])->name('categorias.destroy');*/
|
||||||
Loading…
Reference in New Issue
Block a user