init
This commit is contained in:
62
app/Http/Controllers/Api/ProductController.php
Normal file
62
app/Http/Controllers/Api/ProductController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ProductRequest;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$products = Product::all();
|
||||
return Inertia::render('dashboard/product/index', ['products' => $products]);
|
||||
}
|
||||
|
||||
public function show()
|
||||
{
|
||||
$products = Product::where('display_status', '=', 'active')->get();
|
||||
return Inertia::render('dashboard/product', ['products' => $products]);
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return Inertia::render('dashboard/product/add');
|
||||
}
|
||||
|
||||
public function edit(string $id)
|
||||
{
|
||||
$products = Product::find($id);
|
||||
return Inertia::render('dashboard/product/edit', ['products' => $products]);
|
||||
}
|
||||
|
||||
public function store(ProductRequest $request)
|
||||
{
|
||||
$validate = $request->validated();
|
||||
|
||||
Product::create($validate);
|
||||
|
||||
return to_route('product.index');
|
||||
}
|
||||
|
||||
public function update(ProductRequest $request, string $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
|
||||
$product->update($request->validated());
|
||||
|
||||
return to_route('product.index');
|
||||
}
|
||||
|
||||
public function delete(string $id)
|
||||
{
|
||||
$product = Product::find($id);
|
||||
|
||||
$product->delete();
|
||||
|
||||
return to_route('product.index');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user