pai-sklep/app/Http/Controllers/ProductController.php

97 lines
2.4 KiB
PHP
Raw Permalink Normal View History

2021-09-05 02:22:17 +02:00
<?php
namespace App\Http\Controllers;
use App\Models\Product;
use Illuminate\Http\Request;
2021-10-28 11:19:42 +02:00
use Illuminate\Support\Facades\Log;
2021-09-05 02:22:17 +02:00
class ProductController extends Controller
{
public function index()
{
2021-10-28 11:19:42 +02:00
// TMP do something better at some point maybe idk
return redirect()->route("product.create");
2021-09-05 02:22:17 +02:00
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
2021-10-28 11:19:42 +02:00
return view("product/create");
2021-09-05 02:22:17 +02:00
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
2021-10-28 11:19:42 +02:00
Log::debug($request);
$request->validate([
'name'=>'required',
'description'=>'required',
]);
$product = new Product([
'name' => $request->get("name"),
'description' => $request->get("description")
]);
$product->save();
//echo $product->uuid;
return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully");
2021-09-05 02:22:17 +02:00
}
/**
* Display the specified resource.
*
* @param \App\Models\Product $product
* @return \Illuminate\Http\Response
*/
public function show(Product $product)
{
2021-10-28 11:19:42 +02:00
return view("product/view", ["product" => $product]);
2021-09-05 02:22:17 +02:00
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Product $product
* @return \Illuminate\Http\Response
*/
public function edit(Product $product)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Product $product
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $product)
{
2021-10-28 11:19:42 +02:00
$product->fill($request->all());
$product->save();
return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully");
2021-09-05 02:22:17 +02:00
}
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Product $product
* @return \Illuminate\Http\Response
*/
public function destroy(Product $product)
{
2021-10-28 11:19:42 +02:00
$product->delete();
return redirect()->route("product.index");
2021-09-05 02:22:17 +02:00
}
}