Skip to content

Commit 54dbf17

Browse files
author
ahmadhuss
committed
refactor: Added body of update ProductController.php
1 parent 3b3c633 commit 54dbf17

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

app/Http/Controllers/ProductController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function show($id)
6868
*/
6969
public function edit($id)
7070
{
71-
$categories = Category::all();
7271
$product = Product::findOrFail($id);
72+
$categories = Category::all();
7373
return view('products.edit', compact('categories', 'product'));
7474
}
7575

@@ -82,7 +82,15 @@ public function edit($id)
8282
*/
8383
public function update(Request $request, $id)
8484
{
85-
//
85+
$product = Product::findOrFail($id);
86+
$product->update([
87+
'name' => $request->name,
88+
'price' => $request->price,
89+
'category_id' => $request->category_id,
90+
'description' => $request->description,
91+
'photo' => ''
92+
]);
93+
return redirect()->route('products.index');
8694
}
8795

8896
/**

resources/views/products/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<div class="my-2">
1515
<label for="nameInput" class="d-block">Name:</label>
16-
<input type="text" class="form-control" name="name" id="nameInput" value={{ $product->name }}/>
16+
<input type="text" class="form-control" name="name" id="nameInput" value="{{ $product->name }}"/>
1717
</div>
1818

1919
<div class="my-2">

0 commit comments

Comments
 (0)