Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 6, 2020 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/b2349b647909e96ef8494d1e1517dae5 to your computer and use it in GitHub Desktop.
Save parzibyte/b2349b647909e96ef8494d1e1517dae5 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Producto;
use Illuminate\Http\Request;
class ProductosController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view("productos.productos_index", ["productos" => Producto::all()]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view("productos.productos_create");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$producto = new Producto($request->input());
$producto->saveOrFail();
return redirect()->route("productos.index")->with("mensaje", "Producto guardado");
}
/**
* Display the specified resource.
*
* @param \App\Producto $producto
* @return \Illuminate\Http\Response
*/
public function show(Producto $producto)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Producto $producto
* @return \Illuminate\Http\Response
*/
public function edit(Producto $producto)
{
return view("productos.productos_edit", ["producto" => $producto,
]);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Producto $producto
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Producto $producto)
{
$producto->fill($request->input());
$producto->saveOrFail();
return redirect()->route("productos.index")->with("mensaje", "Producto actualizado");
}
/**
* Remove the specified resource from storage.
*
* @param \App\Producto $producto
* @return \Illuminate\Http\Response
*/
public function destroy(Producto $producto)
{
$producto->delete();
return redirect()->route("productos.index")->with("mensaje", "Producto eliminado");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment