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)) +
There are no items yet. Include one with the form above.
@endforelse -