mirror of
https://github.com/brunofontes/shareit.git
synced 2025-11-15 16:00:54 -03:00
Including Items and Products views and controllers
This commit is contained in:
@@ -23,6 +23,7 @@ class HomeController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('home');
|
||||
$items = \App\Item::where('userID');
|
||||
return view('home', compact('items'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user