public function store(Request $request)
{
$validated = $request->validate([
'product_id' => 'required|exists:products,id',
'quantity' => 'required|integer|min:1',
]);
$product = Product::findOrFail($validated['product_id']);
$totalPrice = $product->price * $validated['quantity'];
$order = Order::create([
'product_id' => $validated['product_id'],
'quantity' => $validated['quantity'],
'total_price' => $totalPrice,
]);
return $order;
}
These methods will handle the API requests for products, categories, and orders, ensuring that the frontend can interact with the backend effectively.