diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 0aa0fc3..c0f0328 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -35,7 +35,7 @@ class ProductController extends Controller { //TODO: Delete all items with all users for the product $request->validate(['product' => 'required']); - $item = User::find(\Auth::id()) + $item = User::findOrFail(\Auth::id()) ->items()->with('users')->find(request('item')); $product = $item->product_id; @@ -51,11 +51,12 @@ class ProductController extends Controller public function patch(Request $request) { - $request->validate(['item' => 'required', 'name' => 'required']); - $item = User::find(\Auth::id())->items()->find(request('item')); - $item->name = request('name'); - $item->save(); - return redirect('item/'.request('item')); + $request->validate(['product' => 'required', 'name' => 'required']); + $product = User::find(\Auth::id())->products()->find(request('product')); + $product->name = request('name'); + $product->url = request('url'); + $product->save(); + return redirect('product/'.request('product')); } /** diff --git a/resources/views/product/addItemForm.blade.php b/resources/views/product/addItemForm.blade.php new file mode 100644 index 0000000..5038106 --- /dev/null +++ b/resources/views/product/addItemForm.blade.php @@ -0,0 +1,14 @@ +
+{{ csrf_field() }} + +
+
+
+
+ +
+
+
+ +@include ('layouts.errors') +
\ No newline at end of file diff --git a/resources/views/product/addProductForm.blade.php b/resources/views/product/addProductForm.blade.php new file mode 100644 index 0000000..5b870bb --- /dev/null +++ b/resources/views/product/addProductForm.blade.php @@ -0,0 +1,19 @@ +
+{{ csrf_field() }} +
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+@include ('layouts.errors') +
\ No newline at end of file diff --git a/resources/views/product/buttons.blade.php b/resources/views/product/buttons.blade.php deleted file mode 100644 index 1d32f34..0000000 --- a/resources/views/product/buttons.blade.php +++ /dev/null @@ -1,46 +0,0 @@ - -
- - - -
- @method('PATCH') - -
- - - -
- {{ csrf_field() }} - @method('DELETE') - -
-
- - - - -
\ No newline at end of file diff --git a/resources/views/product/deleteButton.blade.php b/resources/views/product/deleteButton.blade.php new file mode 100644 index 0000000..7886f83 --- /dev/null +++ b/resources/views/product/deleteButton.blade.php @@ -0,0 +1,28 @@ + + + + \ No newline at end of file diff --git a/resources/views/product/editButton.blade.php b/resources/views/product/editButton.blade.php new file mode 100644 index 0000000..9d6d440 --- /dev/null +++ b/resources/views/product/editButton.blade.php @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/resources/views/product/index.blade.php b/resources/views/product/index.blade.php index 5748826..d944c11 100644 --- a/resources/views/product/index.blade.php +++ b/resources/views/product/index.blade.php @@ -4,19 +4,8 @@
- -
-
- {{ csrf_field() }} -
-
-
-
- @include ('layouts.errors') -
-
-
Products
+
Products
@if (session('status')) @@ -35,6 +24,11 @@
+
+
Add product
+
@include('product.addProductForm')
+
+
diff --git a/resources/views/product/show.blade.php b/resources/views/product/show.blade.php index 473bc00..1e88a90 100644 --- a/resources/views/product/show.blade.php +++ b/resources/views/product/show.blade.php @@ -5,21 +5,18 @@
-
-
- {{ csrf_field() }} -
-
- -
-
- @include ('layouts.errors') -
-
- Product: {{$product['name']}} - @include ('product.buttons') + {{$product['name']}} + @if ($product['url']) + ({{$product['url']}}) + @endif + +
+ @include ('product.editButton') + @include ('product.deleteButton') +
+
@@ -38,6 +35,13 @@
+ +
+
Add item
+
@include('product.addItemForm')
+
+ +
diff --git a/routes/web.php b/routes/web.php index 4776feb..d44ab98 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,6 +18,8 @@ Route::get('/', function () { Route::get('/product', 'ProductController@index')->middleware('auth'); Route::get('/product/{product}', 'ProductController@show')->middleware('auth'); Route::post('/product', 'ProductController@store')->middleware('auth'); +Route::patch('/product', 'ProductController@patch')->middleware('auth'); +Route::delete('/product', 'ProductController@delete')->middleware('auth'); Route::get('/item', 'ItemController@index')->middleware('auth'); Route::get('/item/{item}', 'ItemController@show')->middleware('auth');