Skip to content

Commit

Permalink
feat: Updated app/Http/Controllers/ProductControll
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Mar 11, 2024
1 parent 637f1d7 commit 496d499
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,23 @@ class ProductController extends Controller
{
public function create(Request $request)
{
// Handle Product File Upload
if ($request->hasFile('product_file')) {
$file = $request->file('product_file');
$filePath = $file->store('public/downloadable_products');
$fileUrl = Storage::url($filePath);
} else {
$fileUrl = null;
}

$validatedData = $request->validate([
'name' => 'required|string|max:255',
'description' => 'required|string',
'price' => 'required|numeric',
'category' => 'required|string|max:255',
'inventory_count' => 'required|integer',
// Include download limit in validation
'download_limit' => 'integer|nullable',
]);

$product = Product::create($validatedData);
Expand Down Expand Up @@ -57,6 +68,15 @@ public function update(Request $request, $id)
'inventory_count' => 'integer',
]);

// Handle Product File Upload for Update
if ($request->hasFile('product_file')) {
$file = $request->file('product_file');
$filePath = $file->store('public/downloadable_products');
$fileUrl = Storage::url($filePath);
// Update Downloadable Product entry
$product->downloadable()->updateOrCreate(['product_id' => $product->id], ['file_url' => $fileUrl, 'download_limit' => $request->download_limit]);
}

$product->update($validatedData);

return response()->json($product);
Expand Down

0 comments on commit 496d499

Please sign in to comment.