diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index a3af7dd..e8c7929 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -23,6 +23,7 @@ class HomeController extends Controller */ public function index() { - return view('home'); + $items = \App\Item::where('userID'); + return view('home', compact('items')); } } diff --git a/app/Http/Controllers/ItemController.php b/app/Http/Controllers/ItemController.php index c8d9eda..1875944 100644 --- a/app/Http/Controllers/ItemController.php +++ b/app/Http/Controllers/ItemController.php @@ -17,7 +17,7 @@ class ItemController extends Controller public function show($id) { - $item = Item::find($id); + $item = Item::where([['id', $id], ['userID', \Auth::id()]]); return view('item', compact('item')); } } diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index 2f13d44..b7d7647 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -4,20 +4,57 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use \App\Product; +use \App\User; class ProductController extends Controller { // public function index() { - //$product = Product::all(); - return view('product'); + $products = Product::where('adminID', \Auth::id())->get(); + return view('product.index', compact('products')); } + /** + * Stores the included product into database + * + * @return (view) The product view + */ + public function store() + { + /* + $product = new Product; + $product->name = request('product'); + $product->adminID = $userID; + $product->save(); + */ + Product::create(['name' => request('product'), 'adminID' => \Auth::id()]); //Just remember to add the fillable on Model to make this work + + return redirect('product'); + } + + /** + * Delete a specified Product + * + * @param (int) $id The product id + */ + public function delete($id) + { + } + + /** + * Show a specified Product + * + * @param (int) $id The product id + */ public function show($id) { - //$productID = Product::find($id); - $productID = $id; - return view('product', compact('productID')); + $product = Product::find($id); + $items = \DB::table('items') + ->join('products', 'items.productID', '=', 'products.id') + ->where('products.adminID', \Auth::id()) + ->select('items.*', 'products.*') + ->get(); + return view('product.show', compact('items', 'product')); } } diff --git a/app/Item.php b/app/Item.php index bd56790..f2780bd 100644 --- a/app/Item.php +++ b/app/Item.php @@ -7,9 +7,10 @@ use Illuminate\Database\Eloquent\Model; class Item extends Model { // - public function free($productID) + public function free($productID, $userID) { return $query->where([ + ['userID', $userID], ['productID', $productID], ['usedBy', ''], ]); diff --git a/app/Product.php b/app/Product.php index 8dee5b2..afa05e9 100644 --- a/app/Product.php +++ b/app/Product.php @@ -6,5 +6,6 @@ use Illuminate\Database\Eloquent\Model; class Product extends Model { + protected $fillable = ['adminID', 'name']; // } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 05dfca9..e05d426 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -14,7 +14,12 @@ @endif - You are logged in! +
There are no items for you yet. Include one here.
+ @endforelse diff --git a/resources/views/product/index.blade.php b/resources/views/product/index.blade.php new file mode 100644 index 0000000..5c568d0 --- /dev/null +++ b/resources/views/product/index.blade.php @@ -0,0 +1,41 @@ +@extends('layouts.app') + +@section('content') +There are no products yet. Include one with the form above.
+ @endforelse +There are no items yet. Include one with the form above.
+ @endforelse +