Files
col-thinkspace/app/Http/Controllers/Api/ProductController.php
Chief-spartan-117 972264e361
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
init
2026-01-21 11:13:09 +05:45

63 lines
1.4 KiB
PHP

<?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');
}
}