From 3db5c3862bbb7d5c18b022682438fc2f46ca7cc5 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Mon, 10 Sep 2018 21:29:32 -0300 Subject: [PATCH] Including item and product form validation --- app/Http/Controllers/ItemController.php | 32 ++++++++++++++++------ app/Http/Controllers/ProductController.php | 1 - resources/views/layouts/errors.blade.php | 11 ++++++++ resources/views/product/index.blade.php | 6 ++-- resources/views/product/show.blade.php | 7 ++--- 5 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 resources/views/layouts/errors.blade.php diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index 1875944..c74f90c 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -7,17 +7,33 @@ use \App\Item; class ItemController extends Controller { - // - public function index() - { - //$item = Item::all(); - //return $item; //Show a JSON file instead of the view - return view('item'); - } - public function show($id) { + //TODO: Fazer innerjoint com tabela de users por item $item = Item::where([['id', $id], ['userID', \Auth::id()]]); return view('item', compact('item')); } + + public function index() + { + //TODO: Fazer innerjoint com tabela de users por item + $items = Item::where('adminID', \Auth::id())->get(); + return view('item.index', compact('items')); + } + + /** + * Stores the included item into database + * As the items are included on the Product view, + * it must return to there after inclusion + * + * @return (view) The product view + */ + public function store() + { + $this->validate(request(), ['name' => 'required']); + Item::create(['name' => request('item'), 'productID' => request('productID')]); //Just remember to add the fillable on Model to make this work + + return redirect('product'); + } + } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index b7d7647..eb756fc 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -8,7 +8,6 @@ use \App\User; class ProductController extends Controller { - // public function index() { $products = Product::where('adminID', \Auth::id())->get(); diff --git a/resources/views/layouts/errors.blade.php b/resources/views/layouts/errors.blade.php new file mode 100644 index 0000000..bea0b77 --- /dev/null +++ b/resources/views/layouts/errors.blade.php @@ -0,0 +1,11 @@ +@if (count($errors)) +
+
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+
+@endif \ No newline at end of file diff --git a/resources/views/product/index.blade.php b/resources/views/product/index.blade.php index 5c568d0..5748826 100644 --- a/resources/views/product/index.blade.php +++ b/resources/views/product/index.blade.php @@ -9,13 +9,13 @@
{{ csrf_field() }}
-
+
+ @include ('layouts.errors') -


-
+
Products
diff --git a/resources/views/product/show.blade.php b/resources/views/product/show.blade.php index 7de5873..1a0c510 100644 --- a/resources/views/product/show.blade.php +++ b/resources/views/product/show.blade.php @@ -9,13 +9,13 @@
{{ csrf_field() }}
-
+
+ @include ('layouts.errors') -


-
+
Product: {{$product['name']}} Edit - Delete @@ -34,7 +34,6 @@

There are no items yet. Include one with the form above.

@endforelse -